ZPOPMAX
ZPOPMAX 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
ZPOPMAX removes and returns the member with the highest score from the
sorted set at key, together with its score. With count, it removes and
returns up to count members, highest score first. When the sorted set
becomes empty, the key is deleted.
To wait for a member when the set is empty, use BZPOPMAX.
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> ZPOPMAX board1) "c"2) "3"127.0.0.1:6379> ZPOPMAX board 21) "b"2) "2"3) "a"4) "1"With RESP3 (redis-cli -3) and a count, each pair is nested:
127.0.0.1:6379> ZADD board 1 "a" 2 "b"(integer) 2127.0.0.1:6379> ZPOPMAX board 21) 1) "b" 2) (double) 22) 1) "a" 2) (double) 1Compatibility
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.