ZREMRANGEBYLEX(3valkey)
π ZREMRANGEBYLEX β the valkey manual, bestie edition
ok so you're reading the ZREMRANGEBYLEX(3valkey) page from the Valkey Command Manual and honestly? you came to the right place. pull up a chair, we're deleting things by alphabetical order today and it's gonna be iconic. β¨
πΈ NAME
zremrangebylex β removes members in a sorted set within a lexicographical range. and the drama? if every single member got removed, it deletes the sorted set entirely. gone. no notes. π
β¨ SYNOPSIS
ZREMRANGEBYLEX key min max
three little args, one big vibe check for your sorted set. π
π«Ά DESCRIPTION
okay so picture this: all the elements in your sorted set were inserted with the same score. why? because you wanted to force lexicographical ordering β like, alphabetical-ish, but make it sorted set. respect.
when that's the situation, this command removes all the elements in the sorted set stored at key that fall between the lexicographical range specified by min and max. π¦
and the meaning of min and max? literally exactly the same as ZRANGEBYLEX. same rules, same energy. and here's the thing that makes it click β this command actually removes the exact same elements that ZRANGEBYLEX would return if you called it with the same min and max arguments. so if you ever wanna preview what's about to get deleted... you already know the move. π
π REPLY
valkey-protocol(7) Integer reply: the number of members removed. that's your body count, bestie. π₯
β‘ COMPLEXITY
O(log(N)+M) β where N is the number of elements in the sorted set and M is the number of elements removed by the operation.
translation: N is the whole squad, M is who actually got voted off the island. ποΈ
π ACL CATEGORIES
@slow@sortedset@write
π HISTORY
- Available since: 2.8.9 β an elder. a legend. she's been doing this. π
π EXAMPLES
ok this is my favorite part, watch her work:
127.0.0.1:6379> ZADD myzset 0 aaaa 0 b 0 c 0 d 0 e
(integer) 5
127.0.0.1:6379> ZADD myzset 0 foo 0 zap 0 zip 0 ALPHA 0 alpha
(integer) 5
127.0.0.1:6379> ZRANGE myzset 0 -1
1) "ALPHA"
2) "aaaa"
3) "alpha"
4) "b"
5) "c"
6) "d"
7) "e"
8) "foo"
9) "zap"
10) "zip"
127.0.0.1:6379> ZREMRANGEBYLEX myzset [alpha [omega
(integer) 6
127.0.0.1:6379> ZRANGE myzset 0 -1
1) "ALPHA"
2) "aaaa"
3) "zap"
4) "zip"
so we added a bunch of stuff with score 0, peeked at the whole set with ZRANGE myzset 0 -1, then ZREMRANGEBYLEX myzset [alpha [omega took out 6 members in one go, and the leftovers were "ALPHA", "aaaa", "zap", "zip". ate and left no crumbs. π
ngl the[and[are the whole plot twist here β inclusive bounds, bestie. iykyk.
π 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)zremrangebyrank(3valkey)zremrangebyscore(3valkey)zrevrange(3valkey)zrevrangebylex(3valkey)zrevrangebyscore(3valkey)zrevrank(3valkey)zscan(3valkey)zscore(3valkey)zunion(3valkey)zunionstore(3valkey)
and that's the whole page!! π this was 9.0.0, dated 2025-10-21, straight from the Valkey Command Manual β go forth and delete things lexicographically, you absolute main character. mwah. πβ¨π¦
π¦ 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