lpop.3valkey - Man Page
Returns the first elements in a list after removing it. Deletes the list if the last element was popped.
Synopsis
LPOP
key [count]
Description
Removes and returns the first elements of the list stored at key
.
By default, the command pops a single element from the beginning of the list. When provided with the optional count
argument, the reply will consist of up to count
elements, depending on the list’s length.
Reply
Resp2
One of the following:
- valkey-protocol(7) Nil reply: if the key does not exist.
- valkey-protocol(7) Bulk string reply: when called without the count argument, the value of the first element.
- valkey-protocol(7) Array reply: when called with the count argument, a list of popped elements.
Resp3
One of the following:
- valkey-protocol(7) Null reply: if the key does not exist.
- valkey-protocol(7) Bulk string reply: when called without the count argument, the value of the first element.
- valkey-protocol(7) Array reply: when called with the count argument, a list of popped elements.
Complexity
O(N) where N is the number of elements returned
Acl Categories
@fast @list @write
History
- Available since: 1.0.0
- Changed in 6.2.0: Added the
count
argument.
Examples
127.0.0.1:6379> RPUSH mylist "one" "two" "three" "four" "five" (integer) 5 127.0.0.1:6379> LPOP mylist "one" 127.0.0.1:6379> LPOP mylist 2 1) "two" 2) "three" 127.0.0.1:6379> LRANGE mylist 0 -1 1) "four" 2) "five"
See Also
blmove(3valkey), blmpop(3valkey), blpop(3valkey), brpop(3valkey), lindex(3valkey), linsert(3valkey), llen(3valkey), lmove(3valkey), lmpop(3valkey), lpos(3valkey), lpush(3valkey), lpushx(3valkey), lrange(3valkey), lrem(3valkey), lset(3valkey), ltrim(3valkey), rpop(3valkey), rpush(3valkey), rpushx(3valkey)