Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

LMPOP

Last updated
LMPOP numkeys key [key ...] LEFT | RIGHT [COUNT count]
Group
List
Complexity
O(N+M) where N is the number of keys checked and M is the number of elements returned
Arity
-4 (at least 4 words, counting the command name)
Flags
write
HotKV Cloud
All plans
On-Premise
no license needed

LMPOP checks the given keys in order and pops from the first one that holds a non-empty list. It pops from the head (LEFT) or the tail (RIGHT), up to count elements (default 1), all from that one list. The list is deleted when it becomes empty.

To wait when every list is empty, use BLMPOP.

Option Effect
numkeys How many keys follow. Must be greater than 0.
LEFT Pop from the head.
RIGHT Pop from the tail.
COUNT count Pop up to count elements. Must be greater than 0. Can be given once.
Case RESP2 RESP3
Popped Two-element array: the key, then an array of the popped elements Same
All keys missing or empty Nil array Null

Errors:

  • ERR numkeys should be greater than 0 if numkeys is not a positive integer.
  • ERR syntax error if fewer keys follow than numkeys says, the direction is missing or not LEFT/RIGHT, or COUNT is repeated or unknown words follow.
  • ERR count should be greater than 0 if count is not a positive integer.
  • WRONGTYPE if a key reached before the first non-empty list holds a value that is not a list.
127.0.0.1:6379> RPUSH q:high h1
(integer) 1
127.0.0.1:6379> RPUSH q:low l1 l2 l3
(integer) 3
127.0.0.1:6379> LMPOP 2 q:high q:low LEFT COUNT 2
1) "q:high"
2) 1) "h1"
127.0.0.1:6379> LMPOP 2 q:high q:low LEFT COUNT 2
1) "q:low"
2) 1) "l1"
2) "l2"
127.0.0.1:6379> LMPOP 1 nosuchkey RIGHT
(nil)

Same as Redis 7.4 and Valkey 8.

BLMPOP, LPOP, RPOP, ZMPOP