简介
- 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
help @list BLPOP key [key ...] timeout summary: Remove and get the first element in a list, or block until one is available since: 2.0.0 BRPOP key [key ...] timeout summary: Remove and get the last element in a list, or block until one is available since: 2.0.0 BRPOPLPUSH source destination timeout summary: Pop a value from a list, push it to another list and return it; or block until one is available since: 2.2.0 LINDEX key index summary: Get an element from a list by its index since: 1.0.0 LINSERT key BEFORE|AFTER pivot value summary: Insert an element before or after another element in a list since: 2.2.0 LLEN key summary: Get the length of a list since: 1.0.0 LPOP key summary: Remove and get the first element in a list since: 1.0.0 LPUSH key value [value ...] summary: Prepend one or multiple values to a list since: 1.0.0 LPUSHX key value summary: Prepend a value to a list, only if the list exists since: 2.2.0 LRANGE key start stop summary: Get a range of elements from a list since: 1.0.0 LREM key count value summary: Remove elements from a list since: 1.0.0 LSET key index value summary: Set the value of an element in a list by its index since: 1.0.0 LTRIM key start stop summary: Trim a list to the specified range since: 1.0.0 RPOP key summary: Remove and get the last element in a list since: 1.0.0 RPOPLPUSH source destination summary: Remove the last element in a list, prepend it to another list and return it since: 1.2.0 RPUSH key value [value ...] summary: Append one or multiple values to a list since: 1.0.0 RPUSHX key value summary: Append a value to a list, only if the list exists since: 2.2.0
队列理解
语雀内容