简介

  • Redis list(列表)双向链表
  • 命令特征:所有命令开始前都带有字母“L”
  • 使用场合:lpush+lpop=Stack(栈)、lpush+rpop=queue(队列)、lpush+brpop=message queue、

lpush+ltrim=Capped Collection(有限集合)

增加

命令 解释
LPUSH key value [value …] 从队列的左边入队一个或多个元素
LPUSHX key value 当队列存在时,从队到左边入队一个元素
RPUSH key value [value …] 从队列的右边入队一个元素
RPUSHX key value 从队列的右边入队一个元素,仅队列存在时有效
LSET key index value 设置队列里面一个元素的值

删除

命令 解释
BLPOP key [key …] timeout 删除,并获得该列表中的第一元素,或阻塞,直到有一个可用
BRPOP key [key …] timeout 删除,并获得该列表中的最后一个元素,或阻塞,直到有一个可用
BRPOPLPUSH source destination timeout 弹出一个列表的值,将它推到另一个列表,并返回它;或阻塞,直到有一个可用
LPOP key 从队列的左边出队一个元素
RPOP key 从队列的右边出队一个元素
LREM key count value 从列表中删除元素
RPOPLPUSH source destination 删除列表中的最后一个元素,将其追加到另一个列表

查询

命令 解释
LINDEX key index 获取一个元素,通过其索引列表
LLEN key 获得队列(List)的长度
LRANGE key start stop 从列表中获取指定返回的元素

修改

命令 解释
LINSERT key BEFORE|AFTER pivot value 在列表中的另一个元素之前或之后插入一个元素
LTRIM key start stop 修剪到指定范围内的清单

其他

http://www.redis.cn/commands.html#list

  1. help @list
  2. BLPOP key [key ...] timeout
  3. summary: Remove and get the first element in a list, or block until one is available
  4. since: 2.0.0
  5. BRPOP key [key ...] timeout
  6. summary: Remove and get the last element in a list, or block until one is available
  7. since: 2.0.0
  8. BRPOPLPUSH source destination timeout
  9. summary: Pop a value from a list, push it to another list and return it; or block until one is available
  10. since: 2.2.0
  11. LINDEX key index
  12. summary: Get an element from a list by its index
  13. since: 1.0.0
  14. LINSERT key BEFORE|AFTER pivot value
  15. summary: Insert an element before or after another element in a list
  16. since: 2.2.0
  17. LLEN key
  18. summary: Get the length of a list
  19. since: 1.0.0
  20. LPOP key
  21. summary: Remove and get the first element in a list
  22. since: 1.0.0
  23. LPUSH key value [value ...]
  24. summary: Prepend one or multiple values to a list
  25. since: 1.0.0
  26. LPUSHX key value
  27. summary: Prepend a value to a list, only if the list exists
  28. since: 2.2.0
  29. LRANGE key start stop
  30. summary: Get a range of elements from a list
  31. since: 1.0.0
  32. LREM key count value
  33. summary: Remove elements from a list
  34. since: 1.0.0
  35. LSET key index value
  36. summary: Set the value of an element in a list by its index
  37. since: 1.0.0
  38. LTRIM key start stop
  39. summary: Trim a list to the specified range
  40. since: 1.0.0
  41. RPOP key
  42. summary: Remove and get the last element in a list
  43. since: 1.0.0
  44. RPOPLPUSH source destination
  45. summary: Remove the last element in a list, prepend it to another list and return it
  46. since: 1.2.0
  47. RPUSH key value [value ...]
  48. summary: Append one or multiple values to a list
  49. since: 1.0.0
  50. RPUSHX key value
  51. summary: Append a value to a list, only if the list exists
  52. since: 2.2.0

队列理解

语雀内容