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.

BLMPOP

Last updated
BLMPOP timeout 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
-5 (at least 5 words, counting the command name)
Flags
write, blocking
HotKV Cloud
All plans
On-Premise
no license needed

BLMPOP is the blocking form of LMPOP. It checks the keys in order and pops up to count elements (default 1) from the head (LEFT) or tail (RIGHT) of the first non-empty list. If every list is empty or missing, the connection waits until one of the keys receives elements or timeout passes, then pops from that key.

timeout is in seconds, can have a fractional part, and 0 waits forever. Inside MULTI / EXEC and inside scripts, BLMPOP never waits and replies at once as if the timeout had expired.

Option Effect
timeout Seconds to wait; 0 waits forever.
numkeys How many keys follow. Must be greater than 0.
LEFT / RIGHT Pop from the head or the tail.
COUNT count Pop up to count elements. Must be greater than 0.

The arguments after timeout are checked before timeout itself.

Case RESP2 RESP3
Popped Two-element array: the key, then an array of the popped elements Same
Timeout expired Nil array Null

Errors:

  • ERR numkeys should be greater than 0, ERR count should be greater than 0, or ERR syntax error, as for LMPOP.
  • ERR timeout is not a float or out of range, ERR timeout is negative, or ERR timeout is out of range for a bad timeout.
  • 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:low l1 l2 l3
(integer) 3
127.0.0.1:6379> BLMPOP 5 2 q:high q:low RIGHT COUNT 2
1) "q:low"
2) 1) "l3"
2) "l2"
127.0.0.1:6379> BLMPOP 0.2 1 q:high LEFT
(nil)
(0.20s)

Same as Redis 7.4 and Valkey 8.

LMPOP, BLPOP, BRPOP, BZMPOP