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 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
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个)字符 [] 匹配括号间的任一个字符, ...
随机推荐
- python中 “与,或,异或”
在python编程语言里面: 按位的运算,都按位的运算,都是把参加运算的数的二进制形式进行运算. 1.与运算:A与B值均为1时,A.B与的运算结果才为1,否则为0 (运算符:&) 2.或运算: ...
- Oracle控制文件丢失,日志文件丢失
控制文件丢失: alter database backup controlfile to traces; shutdown immediate; @j:\db\script\orcl_ora_ctl_ ...
- Hbase实例
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.had ...
- uCGUI窗口的创建过程分析
一.相关结构体和变量 窗口管理结构体 /* 窗口管理结构体 共30个字节 */ struct WM_Obj { GUI_RECT Rect; //窗口尺寸(x0,y0,x1,y1) 8个字节 GUI_ ...
- 一步步学习ASP.NET MVC3 (15)——过滤器
请注明转载地址:http://www.cnblogs.com/arhat 今天老魏和大家一起讨论一下ASP.NET MVC中非常重要的一个知识:"过滤器".那么这个"过滤 ...
- Python 知识点
1. generator #g is a generator and g is iterable g = (x*x for x in range(5)) for n in g: print(n) # ...
- .net 访问远程的MSSQL报System.AccessViolationException错误的解决方法
访问远程的数据库时 报错,本地数据库正常 netsh winsock reset --运行此命令,解决. netsh winsock reset命令,作用是重置 Winsock 目录.如果一台机器 ...
- 分布式系统之CAP理论
任老师第一节主要讲了分布式系统实现时候面临的八个问题,布置的作业就是这个,查询CAP理论. 笔者初次接触分布式,所以本文主要是一个汇总. 一.CAP起源 CAP原本是一个猜想,2000年PODC大会的 ...
- Oracle DB优化
http://www.jb51.net/article/77876.htm http://www.jb51.net/article/56881.htm http://danni505.blog.51c ...
- HDU1395+快速幂
#include<stdio.h> int fast_pow( int a,int b,int mod ){ ; ){ == ){ res = res*a%mod; } a = a*a%m ...