ZREVRANK(3valkey)
β¨ NAME β¨
zrevrank β bestie, this one hands you the index of a member in a sorted set, but ordered by descending scores. Biggest score first, no cap. π
πΈ SYNOPSIS πΈ
ZREVRANK key member [WITHSCORE]
π DESCRIPTION π
Okay so picture this: you got a sorted set chilling at key, and you wanna know where member ranks when everything's sorted from high to low. That's literally it. That's the whole vibe. π
The rank (or index, same thing bestie) is 0-based, which means the member with the highest score gets rank 0. Zero. The top of the podium. Main character energy only. π₯
The optional WITHSCORE argument is the glow-up: it supplements the command's reply with the score of the element returned. So you get the rank and the score, like a little combo meal. π
And if you want the rank ordered from low to high instead? That's ZRANK's job, not hers. Different girl, different energy. π
π¦ REPLY π¦
π RESP2
One of the following, bestie:
valkey-protocol(7)Nil reply: if thekeydoes not exist or thememberdoes not exist in the sorted set. (aka ghosted π)valkey-protocol(7)Integer reply: The rank of thememberwhenWITHSCOREis not used.valkey-protocol(7)Array reply: The rank and score of thememberwhenWITHSCOREis used.
π RESP3
One of the following, same energy different protocol:
valkey-protocol(7)Null reply: if thekeydoes not exist or thememberdoes not exist in the sorted set.valkey-protocol(7)Integer reply: The rank of thememberwhenWITHSCOREis not used.valkey-protocol(7)Array reply: The rank and score of thememberwhenWITHSCOREis used.
π₯ COMPLEXITY π₯
O(log(N)) β fast, efficient, iconic. She's not doing allat. β‘
π ACL CATEGORIES π
@fast @read @sortedset
π HISTORY π
- Available since: 2.0.0 (an elder, honestly, she's been here)
- Changed in 7.2.0: Added the optional
WITHSCOREargument. The glow-up era. β¨
πΈ EXAMPLES πΈ
Watch her work, bestie:
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> ZREVRANK myzset "one"
(integer) 2
127.0.0.1:6379> ZREVRANK myzset "four"
(nil)
127.0.0.1:6379> ZREVRANK myzset "three" WITHSCORE
1) (integer) 0
2) "3"
127.0.0.1:6379> ZREVRANK myzset "four" WITHSCORE
(nil)
See how "three" with score 3 snagged rank 0? Highest score, highest rank spot. Periodt. π
And "four"? Not in the set, so she said (nil) and moved on. Not her problem. π
π«Ά 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), zrevrange(3valkey), zrevrangebylex(3valkey), zrevrangebyscore(3valkey), zscan(3valkey), zscore(3valkey), zunion(3valkey), zunionstore(3valkey)
The whole sorted-set friend group, fr fr. Go say hi. π§
okay that's the whole page bestie, you ate π
This one's from Valkey version 9.0.0, dated 2025-10-21, and yeah, it's the ZREVRANK(3valkey) page β now go rank something. Slay. ππΈ
π¦ 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