redis ltrim命令

摘要:
LTRIMkeystartstop相关命令BLPOPBRPOPBRPOPLPUSHLINDEXLINSERTLLENLPOPLPUSHLPUSHXLRANGELREMLSETLTRIMRPOPRPOPLPUSHRPUSHRPUSHX加入版本1.0.0。时间复杂度:O(N)whereNisthenumberofelementstoberemovedbytheoperation。Trimanexist
LTRIMkey 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. Bothstartandstopare zero-based indexes, where0is the first element of the list (the head),1the next element and so on.

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

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

Out of range indexes will not produce an error: ifstartis larger than the end of the list, orstart > end, the result will be an empty list (which causeskeyto be removed). Ifendis larger than the end of the list, Redis will treat it like the last element of the list.

A common use ofLTRIMis together withLPUSH/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 wayLTRIMis anO(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命令》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇mongodb的配置参数win10 Git安装或者使用出现128问题下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

使用jsPlumb插件实现动态连线功能

jsPlumb是一个强大的JavaScript连线库,它可以将html中的元素用箭头、曲线、直线等连接起来,适用于开发Web上的图表、建模工具等,其实jsPlumb可能主要是用来做流程图的,它在实现这方面的功能上非常强大,我在项目中只使用了它少部分功能,来实现项目中连线的效果。...

Ubuntu 下查看CPU 信息命令

看看带有“处理器”一词的行数,即逻辑CPU的数量。因此,您可以在cmd下输入以下命令:cat/proc/cpuinfo|greproprocessor|wc-l因此,C++程序自然会想到使用strstr函数来查找processor关键字的出现次数。...

Vue 引入 svg文件

在图标显示中,通常使用font真棒图标库,它很简单,只需下载和导入即可。重要的显示:内联块;}2.在src目录下,添加一个名为icons的文件夹,并在icons文件夹下添加索引。js文件和svg文件夹,其中svg文件存储在svg文件夹中。...

Fiddler抓包7-post请求(json)(转载)

2.查看上图中的红色框:这里只支持application/x-www-form-urlencoded格式的body参数,即json格式。您需要检查JOSN列中的five和xml。1.如果遇到text/xml格式的正文,如下图所示...

springMVC使用map接收入参 + mybatis使用map 传入查询参数

测试示例:控制器层使用映射来接收请求参数。从Debug中可以看到,请求中的参数值都是字符串形式。如果接收参数的映射直接传输到服务,mybatis将在接收参数时报告错误。因此,您需要首先对请求中的参数1packageorg.slsale进行预处理。测验23导入java.util。日期4导入java.util。HashMap;5导入java.ut...

ArchLinux安装英伟达显卡驱动

Optimus manager qt Install novausudopacman-Sxf86-video novau右键单击导航栏上的Intel图标,选择列表中的设置功能,单击左侧的Optimus,然后在右侧窗口中选择nouveau作为切换方法。右键单击导航栏上的Intel图标以选择要使用的图形卡类型。在我选择Nvidia显卡后,您需要注销并再次登录才能...