ZREMRANGEBYLEX(3valkey)

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

πŸ’… 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


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