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.

BZPOPMAX

Last updated
BZPOPMAX key [key ...] timeout
Group
Sorted set
Complexity
O(log(N)) where N is the size of the sorted set
Arity
-3 (at least 3 words, counting the command name)
Flags
write, blocking, fast
Keys
first 1, last -2, step 1
HotKV Cloud
All plans
On-Premise
no license needed

BZPOPMAX is the blocking form of ZPOPMAX. It works like BZPOPMIN, but pops the member with the highest score. If every given sorted set is empty or missing, the connection waits until one of the keys gets a member or timeout passes.

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

Case RESP2 RESP3
Member popped Three-element array: the key, the member, the score (bulk string) Three-element array: key, member, score (double)
Timeout expired Nil array Null

Errors:

  • 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"
(integer) 2
127.0.0.1:6379> BZPOPMAX board 0
1) "board"
2) "alice"
3) "100"

Same as Redis 7.4 and Valkey 8.

BZPOPMIN, ZPOPMAX, BZMPOP, BRPOP