ZPOPMAX(3valkey)
π ZPOPMAX β the "gimme ur top scorers, they're MINE now" command
okay so bestie, welcome to the Valkey Command Manual β¨ this one's called zpopmax and it lives in section 3valkey, and it is literally the vibes of reaching into a sorted set and yanking out the biggest flexes.
β¨ NAME β¨
zpopmax β returns the highest-scoring members from a sorted set after removing them. Deletes the sorted set if the last member was popped. π
πΈ SYNOPSIS πΈ
ZPOPMAX key [count]
π DESCRIPTION π
So here's the tea π« β zpopmax removes and returns up to count members with the highest scores in the sorted set stored at key.
When you leave count unspecified, the default value for count is 1. Periodt.
And listen β specifying a count value that's higher than the sorted set's cardinality will not produce an error. She's chill like that. π When returning multiple elements, the one with the highest score will be the first, followed by the elements with lower scores. So it's giving "ranked, top to bottom, no cap." π
π REPLY π
valkey-protocol(7)Array reply: a list of popped elements and scores. π₯
π§ COMPLEXITY π§
O(log(N)*M) with N being the number of elements in the sorted set, and M being the number of elements popped. Math girlies stay winning. β¨
π ACL CATEGORIES π
@fast @sortedset @write
π¦ HISTORY π¦
- Available since:
5.0.0β she's an icon, she's a legend, and she is the moment. π
π EXAMPLES π
127.0.0.1:6379> ZADD myzset 1 "one"
(integer) 1
127.0.0.1:6379> ZADD myzset 2 "two"
(integer) 1
127.0.0.1:6379> ZADD myzset 3 "three"
(integer) 1
127.0.0.1:6379> ZPOPMAX myzset
1) "three"
2) "3"
see how "three" came out first? that's the highest score, bestie. main character energy, first in line, ate and left no crumbs. π
π SEE ALSO π
bzmpop(3valkey)bzpopmax(3valkey)bzpopmin(3valkey)zadd(3valkey)zcard(3valkey)zcount(3valkey)zdiff(3valkey)zdiffstore(3valkey)zincrby(3valkey)zinter(3valkey)zintercard(3valkey)zinterstore(3valkey)zlexcount(3valkey)zmpop(3valkey)zmscore(3valkey)zpopmin(3valkey)zrandmember(3valkey)zrange(3valkey)zrangebylex(3valkey)zrangebyscore(3valkey)zrangestore(3valkey)zrank(3valkey)zrem(3valkey)zremrangebylex(3valkey)zremrangebyrank(3valkey)zremrangebyscore(3valkey)zrevrange(3valkey)zrevrangebylex(3valkey)zrevrangebyscore(3valkey)zrevrank(3valkey)zscan(3valkey)zscore(3valkey)zunion(3valkey)zunionstore(3valkey)
and that's the whole page bestie!! π«Ά this was Valkey version 9.0.0, dated 2025-10-21, and honestly? iconic of her. go pop some maxes, ily, mwah ππ
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms