LPUSH
Syntax
LPUSH key element [element ...]
- Available since:
- 1.0.0
- Time complexity:
- O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.
- ACL categories:
-
@write
,@list
,@fast
,
将所有指定的值插入存储在key
的列表的头部。
如果key
不存在,则在执行推送操作之前将其创建为空列表。
当key
持有的值不是列表时,将返回错误。
可以通过在命令末尾指定多个参数,使用单个命令调用推送多个元素。
元素从最左边的元素到最右边的元素依次插入到列表的头部。
因此,例如命令 LPUSH mylist a b c
将生成一个列表,其中 c
作为第一个元素,b
作为第二个元素,a
作为第三个元素。
示例
RESP2/RESP3 回复
Integer reply: the length of the list after the push operation.历史
- 从 Redis 2.4.0 版本开始:接受多个
element
参数。