LTRIM key start stop

相关命令

加入版本 1.0.0。

时间复杂度: O(N) where N is the number of elements to be removed by the operation。

Trim an existing list so that it will contain only the specified range of elements specified. Both startand stop are zero-based indexes, where 0 is the first element of the list (the head), 1 the next element and so on.

For example: LTRIM foobar 0 2 will modify the list stored at foobar so that only the first three elements of the list will remain.

start and end can also be negative numbers indicating offsets from the end of the list, where -1 is the last element of the list, -2 the penultimate element and so on.

Out of range indexes will not produce an error: if start is larger than the end of the list, or start > end, the result will be an empty list (which causes key to be removed). If end is larger than the end of the list, Redis will treat it like the last element of the list.

A common use of LTRIM is together with LPUSH / RPUSH. For example:

LPUSH mylist someelement
LTRIM mylist 0 99

This pair of commands will push a new element on the list, while making sure that the list will not grow larger than 100 elements. This is very useful when using Redis to store logs for example. It is important to note that when used in this way LTRIM is an O(1) operation because in the average case just one element is removed from the tail of the list.

Return value

Status code reply

Examples

redis> RPUSH mylist "one"

(integer) 1

redis> RPUSH mylist "two"

(integer) 2

redis> RPUSH mylist "three"

(integer) 3

redis> LTRIM mylist 1 -1

OK

redis> LRANGE mylist 0 -1

1) "two"
2) "three"

redis>

redis ltrim命令的更多相关文章

  1. Redis常用命令入门3:列表类型

    列表类型 列表类型也是一个我们很长要用到的一个类型.比如我们发博客,要用到博客列表.如果没有列表我们就只能遍历键来获取所有文章或一部分文章了,这个语法是keys,但是这个命令需要遍历数据库中的所有键, ...

  2. redis shell命令大全

    redis shell命令大全(转自http://blog.mkfree.com/posts/5105432f975ad0eb7d135964) 作者:oyhk   2013-1-28 3:11:35 ...

  3. 转:redis常用命令

    一 Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发 ...

  4. Redis常用命令入门——列表类型(一级二级缓存技术)

    获取列表片段 redis > LRANGE KEY_NAME START END lrange命令比较常用,返回从start到stop的所有元素的列表,start和stop都是从0开始. (1) ...

  5. Redis操作List工具类封装,Java Redis List命令封装

    Redis操作List工具类封装,Java Redis List命令封装 >>>>>>>>>>>>>>>> ...

  6. Redis相关命令及Jedis的demo(转)

    org.springframework.data.redis.core.RedisTemplate在List操作时的一个注意事项:BoundListOperations boundListOperat ...

  7. 数据库 【redis】 命令大全

    以下纯属搬砖,我用Python抓取的redis命令列表页内容 如果想看命令的具体使用可查去官网查看,以下整理为个人查找方便而已 地理位置GEOADD 将指定的地理空间位置(纬度.经度.名称)添加到指定 ...

  8. 【redis】redis常用命令及操作记录

    redis-cli是Redis命令行界面,可以向Redis发送命令,并直接从终端读取服务器发送的回复. 它有两种主要模式:一种交互模式,其中有一个REPL(read eval print loop), ...

  9. 【命令】Redis常用命令整理

    doc 环境下使用命令:       keys 命令         ?    匹配一个字符         *    匹配任意个(包括0个)字符         []    匹配括号间的任一个字符, ...

随机推荐

  1. jenkins 重新设置 管理员密码

    由于服务器瘫痪,修好之后经常不上,就把jenkins的管理密码忘掉了. 查阅了网上所有方案之后发现没有一个 能正确修改密码的,特此列出下列网上的方法 第一.设成无需密码验证的(网上有教程,不过并不能修 ...

  2. JS-------DOM0级事件处理和DOM2级事件处理-------简单记法

    0级DOM 分为2个:一是在标签内写onclick事件  二是在JS写onlicke=function(){}函数 1) <input id="myButton" type= ...

  3. codeforces edu round3

    B. The Best Gift  传送门:http://codeforces.com/problemset/problem/609/B Emily's birthday is next week a ...

  4. 敏捷开发概述与路线(转自MBAlib)

    敏捷开发的概述 简单的说,敏捷开发是一种以人为核心.迭代.循序渐进的开发方法.在敏捷开发中,软件项目的构建被切分成多个子项目,各个子项目的成果都经过测试,具备集成和可运行的特征.换言之,就是把一个大项 ...

  5. oracle 内置函数 least decode

    在博客园的第一个博客,为什么叫第一个.... oracle 内置函数 east(1,2,3,4.....) 可以有多个值,最多几个?不知道欢迎补充 ,,,) from dual 这个函数返回是1,就是 ...

  6. jvm 性能调优

    [转载]:http://blog.csdn.net/chen77716/article/details/5695893 最近因项目存在内存泄漏,故进行大规模的JVM性能调优 , 现把经验做一记录. 一 ...

  7. ExtJS4.2学习(14)基于表格的扩展插件(2)(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-26/184.html --------------- ...

  8. Angular2经典文章集锦

    Angular Metadata 等基础知识 http://www.jianshu.com/p/aeb11061b82c Metadata告诉Angular如何处理一个类,只有我们将它通告给Angul ...

  9. Linux下打包压缩成war包和解压war包

    一. 打包成war包 因为种种原因公司需要把java程序达成war包.起先用zip命令打包,起先可以用,后来却无法使用.今天找到一个更好的办法.用jar命令,前提是要安装jdk. 把当前目录下的所有文 ...

  10. java this 隐式参数

    第37级 this 是隐式参数, 类的方法调用时,会系统自动传递一个this的参数给方法.(这个参数是隐式传递的) 所以在方法里可以使用this这个参数. this在方法中表示对象. this(参数列 ...