Skip to content

ZPOPMAX

ZPOPMAX key [count]

ZPOPMAX removes and returns the member with the highest score from the sorted set at the specified key.

If the key does not exist, the command returns empty list. An optional “count” argument can be provided to remove and return multiple members (up to the number specified).

When popped, the elements are returned in descending order of score and you get the rank of the element in the sorted set. The rank is 1-based, which means that the first element is at rank 1 and not rank 0. The 1), 2), 3), … is the rank of the element in the sorted set.

localhost:7379> ZADD users 10 alice 20 bob 30 charlie
OK 3
localhost:7379> ZPOPMAX users
OK
3) 30, charlie
localhost:7379> ZPOPMAX users 10
OK
2) 20, bob
1) 10, alice