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. python正则的中文处理

    因工作需要,要查找中文汉字分词,因为python正则表达式\W+表示的是所有的中文字就连标点符号都包括.所以要想办法过滤掉. 参考博客:http://log.medcl.net/item/2011/0 ...

  2. maven之ssh项目搭建

    1:新建maven-archetupe-webapp项目 2:web.xml配置文件如下 <?xml version="1.0" encoding="UTF-8&q ...

  3. Open CASCADE 基础类(Foundation Classes)

    1 介绍(Introduction) 1 如何使用Open CASCADE技术(OCCT)基础类. This manual explains how to use Open CASCADE Techn ...

  4. 【加密】C#.NET 各种加密解密

    包括:AES/DES/Base64/RSA/MD5/SHA256 http://www.sosuo8.com/article/show.asp?id=3083 http://blog.csdn.net ...

  5. Source Insight 显示中文乱码

    Source Insight 3.X utf8支持插件震撼发布 继上次SI多标签插件之后,因为公司内部编码改为utf8编码,因此特意做了这个Source Insight 3.X utf8插件. 下载地 ...

  6. 自动寻路NavMesh

    步骤 1.创建地形 2.添加角色 3.创建多个障碍物,尽量摆放的复杂些,用来检测NavMesh的可用性和效率 4.选中地形,在Navigation窗口中,设置Navigation Static 5.依 ...

  7. 重置mysql密码

    如何修改mysql root密码 忘记MySQL ROOT密码是在MySQ使用中很常见的问题,可是有很多朋友并不会重置ROOT密码,那叫苦啊,特写此文章与大家交流: 1.编辑MySQL的配置文件:my ...

  8. .bat批处理脚本让cmd命令行提示符cd到工作目录 (转)

    打开cmd,检查命令行提示符所在的默认位置(目录),进入该目录用notepad++创建一个文件,输入 @echo offrem 这个符号表示该行是注释.rem 进入f盘,需要先切换盘符,成功后才能进入 ...

  9. 十款优秀的在线JavaScript工具介绍

    JavaScript是Web开发者不可或缺的一项技能,它可以为你的网站添加丰富的交互功能和绚丽的视觉效果,以此来增强用户体验. 本文整理了10款非常优秀的在线JavaScript代码工具,涵盖编辑.压 ...

  10. php的curl获取https加密协议请求返回json数据进行信息获取

    <?php header("Content-type:text/html; charset=utf-8");function getToken($url){        $ ...