BZMPOP
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.
Options
Section titled “Options”| 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.
Return value
Section titled “Return value”| 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, orERR syntax error, as for ZMPOP.ERR timeout is not a float or out of range,ERR timeout is negative, orERR timeout is out of rangefor a badtimeout.WRONGTYPEif a key reached before the first non-empty sorted set holds a value that is not a sorted set.
Examples
Section titled “Examples”127.0.0.1:6379> ZADD board 100 "alice" 90 "bob" 80 "carol"(integer) 3127.0.0.1:6379> BZMPOP 1 1 board MAX COUNT 21) "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)Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.