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.

BZMPOP

Last updated
BZMPOP timeout numkeys key [key ...] MIN | MAX [COUNT count]
Group
Sorted set
Complexity
O(K)+O(M*log(N)) where K is the number of keys checked, N the size of the sorted set and M the number of members popped
Arity
-5 (at least 5 words, counting the command name)
Flags
write, blocking
HotKV Cloud
All plans
On-Premise
no license needed

BZMPOP is the blocking form of ZMPOP. It checks the keys in order and pops up to count members (default 1) from the first non-empty sorted set: the lowest scores with MIN, the highest with MAX. If every sorted set is empty or missing, the connection waits until one of the keys gets members 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, BZMPOP 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.
MIN / MAX Pop the lowest or the highest scores.
COUNT count Pop up to count members. 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 [member, score] pairs (score as a bulk string) Same shape, with each score a double
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 ZMPOP.
  • 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 sorted set holds a value that is not a sorted set.
127.0.0.1:6379> ZADD board 100 "alice" 90 "bob" 80 "carol"
(integer) 3
127.0.0.1:6379> BZMPOP 1 1 board MAX COUNT 2
1) "board"
2) 1) 1) "alice"
2) "100"
2) 1) "bob"
2) "90"
127.0.0.1:6379> BZMPOP 0.3 1 empty MIN
(nil)
(0.30s)

Same as Redis 7.4 and Valkey 8.

ZMPOP, BZPOPMIN, BZPOPMAX, BLMPOP