redis ltrim命令
LTRIM key start stop
相关命令
- BLPOP
- BRPOP
- BRPOPLPUSH
- LINDEX
- LINSERT
- LLEN
- LPOP
- LPUSH
- LPUSHX
- LRANGE
- LREM
- LSET
- LTRIM
- RPOP
- RPOPLPUSH
- RPUSH
- RPUSHX
加入版本 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 start
and 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
Examples
(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命令的更多相关文章
- Redis常用命令入门3:列表类型
列表类型 列表类型也是一个我们很长要用到的一个类型.比如我们发博客,要用到博客列表.如果没有列表我们就只能遍历键来获取所有文章或一部分文章了,这个语法是keys,但是这个命令需要遍历数据库中的所有键, ...
- redis shell命令大全
redis shell命令大全(转自http://blog.mkfree.com/posts/5105432f975ad0eb7d135964) 作者:oyhk 2013-1-28 3:11:35 ...
- 转:redis常用命令
一 Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发 ...
- Redis常用命令入门——列表类型(一级二级缓存技术)
获取列表片段 redis > LRANGE KEY_NAME START END lrange命令比较常用,返回从start到stop的所有元素的列表,start和stop都是从0开始. (1) ...
- Redis操作List工具类封装,Java Redis List命令封装
Redis操作List工具类封装,Java Redis List命令封装 >>>>>>>>>>>>>>>> ...
- Redis相关命令及Jedis的demo(转)
org.springframework.data.redis.core.RedisTemplate在List操作时的一个注意事项:BoundListOperations boundListOperat ...
- 数据库 【redis】 命令大全
以下纯属搬砖,我用Python抓取的redis命令列表页内容 如果想看命令的具体使用可查去官网查看,以下整理为个人查找方便而已 地理位置GEOADD 将指定的地理空间位置(纬度.经度.名称)添加到指定 ...
- 【redis】redis常用命令及操作记录
redis-cli是Redis命令行界面,可以向Redis发送命令,并直接从终端读取服务器发送的回复. 它有两种主要模式:一种交互模式,其中有一个REPL(read eval print loop), ...
- 【命令】Redis常用命令整理
doc 环境下使用命令: keys 命令 ? 匹配一个字符 * 匹配任意个(包括0个)字符 [] 匹配括号间的任一个字符, ...
随机推荐
- hdu 1043 pku poj 1077 Eight (BFS + 康拓展开)
http://acm.hdu.edu.cn/showproblem.php?pid=1043 http://poj.org/problem?id=1077 Eight Time Limit: 1000 ...
- 由abcd四个字符取5个作允许重复的排列,要求a出现次数不超过2次,但不能不出现;b不超过1个;c不超过3个;d出现的次数为偶数。求满足以上条件的排列数。
一.我的解法 由于没复习,我在想一般的方法,那就是d取0.2.4,然后分步计算,得到225这个错误答案. 二.指数型母函数 设满足以上条件取个排列的排列数为,的指数型母函数为 ...
- 从Clarifai的估值聊聊深度学习
从Clarifai的估值聊聊深度学习 [转载请注明出处] 前几天和 Ayden @叶瀚中 聊天时,提到了 www.clarifai.com 这家公司. 此前,我已经从各方消息中听说过创始人Matt Z ...
- hdu 4267
一个很不错的题: 刚刚看到这个题目就感觉要用线段树或者树状数组,但是有感觉有点不同: 敲了一发简单的线段树之后果断的T了: 网上一搜题解,发现要用55颗线段树或者树状数组: 一共有k种树,然后每种树根 ...
- Firefly官方教程之Distributed使用文档
原地址:http://bbs.gameres.com/thread_224191.html distributed使用文档1.distributed说明该模块主要封装了各个服务进程间进行通信的方法.n ...
- FZU 2150 Fire Game(BFS)
点我看题目 题意 :就是有两个熊孩子要把一个正方形上的草都给烧掉,他俩同时放火烧,烧第一块的时候是不花时间的,每一块着火的都可以在下一秒烧向上下左右四块#代表草地,.代表着不能烧的.问你最少花多少时间 ...
- SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-012-AOP总结
1.AOP是面向对象编程的有力补充,它可以让你把分散在应用中的公共辅助功能抽取成模块,以灵活配置,减少了重复代码,让类更关注于自身的功能
- 定时显示提示控件 TToolTip
转载过来的,文章出自: http://www.delphifans.com/infoview/Article_3640.html { 修改者:ghs 日期:20071218 功能:在 ...
- Spring 3.x企业应用开发实战(14)----事务
Spring虽然提供了灵活方便的事务管理功能,但这些功能都是基于底层数据库本身的事务处理机制工作的.要深入了解Spring的事务管理和配置,有必要先对数据库事务的基础知识进行学习. 何为数据库事务 “ ...
- jni.h头文件详解二
作者:左少华 博客:http://blog.csdn.net/shaohuazuo/article/details/42932813 转载请注明出处:http://blog.csdn.net/shao ...