LPOP · Valkey

LPOP

Returns the first elements in a list after removing it. Deletes the list if the last element was popped.

Usage

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:

Reply RESP3

One of the following:

Complexity

O(N) where N is the number of elements returned

ACL Categories

@fast @list @write

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"

History

See also

BLMOVE, BLMPOP, BLPOP, BRPOP, LINDEX, LINSERT, LLEN, LMOVE, LMPOP, LPOS, LPUSH, LPUSHX, LRANGE, LREM, LSET, LTRIM, RPOP, RPUSH, RPUSHX.