LPOP

Syntax

  1. LPOP key [count]

Time complexity: O(N) where N is the number of elements returned

ACL categories: @write, @list, @fast

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.

Return

When called without the count argument:

Bulk string reply: the value of the first element, or nil when key does not exist.

When called with the count argument:

Array reply: list of popped elements, or nil when key does not exist.

Examples

  1. dragonfly> RPUSH mylist "one" "two" "three" "four" "five"
  2. (integer) 5
  3. dragonfly> LPOP mylist
  4. "one"
  5. dragonfly> LPOP mylist 2
  6. 1) "two"
  7. 2) "three"
  8. dragonfly> LRANGE mylist 0 -1
  9. 1) "four"
  10. 2) "five"