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.

ZPOPMIN

Last updated
ZPOPMIN key [count]
Group
Sorted set
Complexity
O(log(N)*M) where N is the size of the sorted set and M is the number of members popped
Arity
-2 (at least 2 words, counting the command name)
Flags
write, fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

ZPOPMIN removes and returns the member with the lowest score from the sorted set at key, together with its score. With count, it removes and returns up to count members, lowest score first. When the sorted set becomes empty, the key is deleted.

To wait for a member when the set is empty, use BZPOPMIN.

Case RESP2 RESP3
No count Two-element array: member, score (bulk string) Two-element array: member, score (double)
With count Flat array: member, score, member, score, … Array of two-element arrays: [member, score], the score a double
Key does not exist, or count is 0 Empty array Empty array

Errors:

  • ERR value is out of range, must be positive if count is negative or not an integer. This is checked before the key is looked up.
  • ERR syntax error if more than one count argument is given.
  • WRONGTYPE if key holds a value that is not a sorted set.
127.0.0.1:6379> ZADD board 1 "a" 2 "b" 3 "c"
(integer) 3
127.0.0.1:6379> ZPOPMIN board
1) "a"
2) "1"
127.0.0.1:6379> ZPOPMIN board 5
1) "b"
2) "2"
3) "c"
4) "3"
127.0.0.1:6379> ZPOPMIN board
(empty array)

Same as Redis 7.4 and Valkey 8.

ZPOPMAX, BZPOPMIN, ZMPOP, ZRANGE