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>

最新文章

  1. 关于conky
  2. Web自动化测试 Selenium 3/3 https的配置
  3. 简单的cookie使用
  4. CoreLocation 下的定位跟踪测速
  5. CSS2书写顺序
  6. c/c++重定向输入输出
  7. MyBatis 原始Dao开发方式
  8. vue-router实例
  9. Go学习——new()和 make()的区别详解(转载)
  10. SQL中内连接和外连接的问题!
  11. udp重发
  12. python笔记1-基础概念、python安装使用配置
  13. SecureCRT乱码解决
  14. October 12th 2017 Week 41st Thursday
  15. BZOJ.4516.[SDOI2016]生成魔咒(后缀数组 RMQ)
  16. FPGA In/Out Delay Timing Constaint
  17. 使用注册表优化终端、编辑器的中英字体混合显示,如「Consolas + 雅黑」「Monaco + 雅黑」
  18. 你使用 Web 平台安装程序命令行工具
  19. schema in oracle
  20. bootstrap-select.js 下拉框多选后动态赋值

热门文章

  1. Oracle 分析函数 "ORA-30485: 在窗口说明中丢失 ORDER BY 表达式"
  2. 在Linux上安装Memcached服务
  3. iOS runloop 资源汇总-b
  4. AVQueuePlayer,备用
  5. apt-get命令讲解
  6. csuoj 1351: Tree Counting
  7. 玩转AWS CloudWatch微信告警
  8. [wikioi]合并果子
  9. spring+mybatis的优缺点
  10. tomcat docBase 和 path