ZPOPMIN
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.
Return value
Section titled “Return value”| 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 positiveifcountis negative or not an integer. This is checked before the key is looked up.ERR syntax errorif more than onecountargument is given.WRONGTYPEifkeyholds a value that is not a sorted set.
Examples
Section titled “Examples”127.0.0.1:6379> ZADD board 1 "a" 2 "b" 3 "c"(integer) 3127.0.0.1:6379> ZPOPMIN board1) "a"2) "1"127.0.0.1:6379> ZPOPMIN board 51) "b"2) "2"3) "c"4) "3"127.0.0.1:6379> ZPOPMIN board(empty array)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.