ZREVRANGEBYLEX(3valkey)
π ZREVRANGEBYLEX π
okay bestie, so this is a page from the Valkey Command Manual, and we're talking about zrevrangebylex(3valkey) β yes the whole name is a mouthful, no I will not be shortening it, it's iconic that way. sit down, grab a strawberry, let's go π
β¨ NAME β¨
zrevrangebylex β returns members in a sorted set within a lexicographical range, but in reverse order. that's it, that's the girl π
π¦ SYNOPSIS π¦
ZREVRANGEBYLEX key max min [LIMIT offset count]
look at her. four things, one optional duo. she's lowkey elegant.
πΈ DESCRIPTION πΈ
okay so here's the vibe: when literally every element in a sorted set got inserted with the same score β the little trick to force lexicographical ordering β this command returns all the elements in the sorted set at key with a value between max and min. the whole squad, in reverse. π
and apart from that reversed ordering? ZREVRANGEBYLEX is basically ZRANGEBYLEX's twin. same energy, opposite direction. fr fr.
π§ Alternative
ZRANGE with the REV and BYLEX arguments. yes bestie, that's the modern shortcut. iykyk π
π REPLY π
valkey-protocol(7) Array reply: a list of the members in the specified score range. so you get a whole lil array back, all your little members lined up π
β COMPLEXITY β
O(log(N)+M) β where N is the number of elements in the sorted set and M is the number of elements being returned.
but listen: if M is constant (like, you're always asking for the first 10 elements with LIMIT), you can consider it O(log(N)). slay. β¨
π₯ ACL CATEGORIES π₯
@read@slow@sortedset
π HISTORY π
- Available since: 2.8.9
she's been here a minute, and she's aged like fine wine π·
π EXAMPLES π
127.0.0.1:6379> ZADD myzset 0 a 0 b 0 c 0 d 0 e 0 f 0 g
(integer) 7
127.0.0.1:6379> ZREVRANGEBYLEX myzset [c -
1) "c"
2) "b"
3) "a"
127.0.0.1:6379> ZREVRANGEBYLEX myzset (c -
1) "b"
2) "a"
127.0.0.1:6379> ZREVRANGEBYLEX myzset (g [aaa
1) "f"
2) "e"
3) "d"
4) "c"
5) "b"
see how [ means inclusive and ( means exclusive? the way that [c gives you "c" and (c does not?? chef's kiss. main character behavior from a bracket. π
π 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), zrevrangebyscore(3valkey), zrevrank(3valkey), zscan(3valkey), zscore(3valkey), zunion(3valkey), zunionstore(3valkey)
that's the whole friend group right there. go read them all, they're all obsessed with you π«Ά
okay that's the whole page bestie, mwah π this was Valkey Command Manual, version 9.0.0, dated 2025-10-21, and yes i memorized all of that for you. periodt. π β¨π¦
π¦ 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