ZREMRANGEBYSCORE(3valkey)

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

✨ ZREMRANGEBYSCORE β€” the valkey glow-up where mid scores get evicted πŸ’…

okay bestie, quick vibe check: this is a page from the Valkey Command Manual, and today's main character is ZREMRANGEBYSCORE. no cap.


πŸ’– NAME πŸ’–

zremrangebyscore β€” removes members in a sorted set within a range of scores. and like, if that range happens to be everybody, it deletes the whole sorted set too. she's thorough. 🫢


🌸 SYNOPSIS 🌸

ZREMRANGEBYSCORE key min max

πŸ¦‹ DESCRIPTION πŸ¦‹

Removes all the elements in the sorted set stored at key whose score sits between min and max. and yes, it's inclusive on both ends, so the boundary girlies get got too. no survivors at the edges, periodt.


πŸŽ€ REPLY πŸŽ€

valkey-protocol(7) Integer reply: the number of members that got removed. she will tell you how many she took out. icon behaviour, honestly.


πŸ‘‘ 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.

like, it's giving logarithmic entrance fee plus a linear cost per member yeeted. not me doing big-O in my head πŸ’€


🌈 ACL CATEGORIES 🌈

  • @slow
  • @sortedset
  • @write

three tags, three vibes, all of them real.


⭐ HISTORY ⭐

  • Available since: 1.2.0 β€” an elder. she's been iconic since before you were on this app. iykyk.

πŸ”₯ EXAMPLES πŸ”₯

okay watch, this is literally the whole plot:

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> ZREMRANGEBYSCORE myzset -inf (2
(integer) 1
127.0.0.1:6379> ZRANGE myzset 0 -1 WITHSCORES
1) "two"
2) "2"
3) "three"
4) "3"

so she built myzset with three besties, then ZREMRANGEBYSCORE myzset -inf (2 wiped everything from -inf up to but not including 2 β€” that ( is doing so much work fr fr πŸ™ˆ β€” and only "one" got taken out. one single casualty. then ZRANGE myzset 0 -1 WITHSCORES shows "two" and "three" still thriving. ate. πŸ“


🧚 SEE ALSO 🧚

the whole friend group, alphabetically, no one left out:

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), zrevrange(3valkey), zrevrangebylex(3valkey), zrevrangebyscore(3valkey), zrevrank(3valkey), zscan(3valkey), zscore(3valkey), zunion(3valkey), zunionstore(3valkey)


πŸ’œ that's the whole page bestie. every flag, every number, every example β€” all intact, none skipped. go forth and evict scores responsibly. 🫢✨

this masterpiece dropped as version 9.0.0 on 2025-10-21, and it's filed under ZREMRANGEBYSCORE(3valkey). mwah. πŸ’…πŸŽ€

πŸ“¦ where this page comes from