ZMPOP
ZMPOP 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
- -4 (at least 4 words, counting the command name)
- Flags
- write
- HotKV Cloud
- All plans
- On-Premise
- no license needed
ZMPOP checks the given keys in order and pops from the first one that holds
a non-empty sorted set. It removes up to count members (default 1), all
from that one sorted set: the lowest scores with MIN, the highest with MAX.
The key is deleted when it becomes empty.
To wait when every sorted set is empty, use BZMPOP.
Options
Section titled “Options”| Option | Effect |
|---|---|
numkeys |
How many keys follow. Must be greater than 0. |
MIN |
Pop the members with the lowest scores. |
MAX |
Pop the members with the highest scores. |
COUNT count |
Pop up to count members. Must be greater than 0. Can be given once. |
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 |
| All keys missing or empty | Nil array | Null |
The pairs are nested under both protocols.
Errors:
ERR numkeys should be greater than 0ifnumkeysis not a positive integer.ERR syntax errorif fewer keys follow thannumkeyssays, the direction is missing or notMIN/MAX, orCOUNTis repeated or unknown words follow.ERR count should be greater than 0ifcountis not a positive integer.WRONGTYPEif a key reached before the first non-empty sorted set holds a value that is not a sorted set (a plain set counts as the wrong type here).
Examples
Section titled “Examples”127.0.0.1:6379> ZADD tasks 3 "low" 1 "urgent" 2 "normal"(integer) 3127.0.0.1:6379> ZMPOP 2 nosuchkey tasks MIN COUNT 21) "tasks"2) 1) 1) "urgent" 2) "1" 2) 1) "normal" 2) "2"127.0.0.1:6379> ZMPOP 1 nosuchkey MAX(nil)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.