ZREVRANGE(3valkey)

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

πŸ’… ZREVRANGE β€” the valkey glow-up page

okay bestie, welcome to the ZREVRANGE(3valkey) page ✨ this one's from the Valkey Command Manual and it's literally so useful, no cap.


🌸 NAME

zrevrange β€” returns members in a sorted set within a range of indexes, but reversed, like the plot twist of sorted sets πŸ’–


✨ SYNOPSIS

ZREVRANGE key start stop [WITHSCORES]

πŸŽ€ DESCRIPTION

So here's the tea: it gives you back the specified range of elements in the sorted set that lives at key. But the elements are ordered from the highest score down to the lowest score β€” top to bottom, main character energy πŸ‘‘. And if two elements have the same score? Descending lexicographical order handles that, periodt.

Other than the whole reversed-order thing, ZREVRANGE is basically ZRANGE's twin 🫢

πŸ” Alternative

ZRANGE with the REV argument. iykyk.


πŸ“¬ REPLY

  • valkey-protocol(7) Array reply β€” a list of the members in the specified range, and if you used WITHSCORE they come with their scores too πŸ’…

⚑ COMPLEXITY

O(log(N)+M) β€” where N is the number of elements in the sorted set and M is the number of elements returned. math but make it slay 🧚


πŸ” ACL CATEGORIES

@read @slow @sortedset


πŸ“œ HISTORY

  • Available since: 1.2.0 β€” an icon from the beginning, fr fr ⭐

🌈 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> ZREVRANGE myzset 0 -1
1) "three"
2) "two"
3) "one"
127.0.0.1:6379> ZREVRANGE myzset 2 3
1) "one"
127.0.0.1:6379> ZREVRANGE myzset -2 -1
1) "two"
2) "one"

look at her go πŸ˜­πŸ’–


πŸ‘€ SEE ALSO


bestie that's the whole page, you're officially a ZREVRANGE girlie now πŸŽ€

and that's a wrap πŸ’œ this one's from Valkey 9.0.0, dated 2025-10-21 β€” mwah, catch you in the next manpage, ily πŸ¦‹βœ¨πŸ“

πŸ“¦ where this page comes from