ZREVRANGE(3valkey)
π 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 usedWITHSCOREthey 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
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)zpopmax(3valkey)zpopmin(3valkey)zrandmember(3valkey)zrange(3valkey)zrangebylex(3valkey)zrangebyscore(3valkey)zrangestore(3valkey)zrank(3valkey)zrem(3valkey)zremrangebylex(3valkey)zremrangebyrank(3valkey)zremrangebyscore(3valkey)zrevrangebylex(3valkey)zrevrangebyscore(3valkey)zrevrank(3valkey)zscan(3valkey)zscore(3valkey)zunion(3valkey)zunionstore(3valkey)
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
- 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