ZPOPMAX(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’… 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 πŸ‘‘


🧚 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 πŸ’–


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