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.

ZMPOP

Last updated
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.

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.
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 0 if numkeys is not a positive integer.
  • ERR syntax error if fewer keys follow than numkeys says, the direction is missing or not MIN/MAX, or COUNT is repeated or unknown words follow.
  • ERR count should be greater than 0 if count is not a positive integer.
  • WRONGTYPE if 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).
127.0.0.1:6379> ZADD tasks 3 "low" 1 "urgent" 2 "normal"
(integer) 3
127.0.0.1:6379> ZMPOP 2 nosuchkey tasks MIN COUNT 2
1) "tasks"
2) 1) 1) "urgent"
2) "1"
2) 1) "normal"
2) "2"
127.0.0.1:6379> ZMPOP 1 nosuchkey MAX
(nil)

Same as Redis 7.4 and Valkey 8.

BZMPOP, ZPOPMIN, ZPOPMAX, LMPOP