What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

ZREMRANGEBYSCORE

Removes members in a sorted set within a range of scores. Deletes the sorted set if all members were removed.

Usage
ZREMRANGEBYSCORE key min max
Complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
Since
1.2.0
ACL Categories
@slow, @sortedset, @write
Command flags
WRITE

Removes all elements in the sorted set stored at key with a score between min and max (inclusive).

Examples

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"

Replies

RESP2

Integer reply: the number of members removed.

RESP3

Integer reply: the number of members removed.