# ZREMRANGEBYSCORE

> Remove the members of a sorted set with scores in a range.

URL: https://docs.hotkv.com/commands/zremrangebyscore/

```
ZREMRANGEBYSCORE key min max
```

- Group: Sorted set
- Complexity: O(log(N)+M) where N is the size of the sorted set and M is the number of members removed
- HotKV Cloud: all plans
- On-Premise: no license needed

`ZREMRANGEBYSCORE` removes every member of the sorted set at `key` whose score
is between `min` and `max`. Bounds are inclusive unless prefixed with `(`, and
`-inf` / `+inf` are allowed. When the sorted set becomes empty, the key is
deleted.

A common use is trimming time-ordered data, for example removing entries whose
score (a timestamp) is older than a cutoff.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Success | Integer: the number of members removed | Same |
| Key does not exist | Integer `0` | Same |

Errors:

- `ERR min or max is not a float` for a bad bound. The bounds are checked
  before the key is looked up.
- `WRONGTYPE` if `key` holds a value that is not a sorted set.

## Examples

```
127.0.0.1:6379> ZADD events 1700000000 "e1" 1700000100 "e2" 1700000200 "e3"
(integer) 3
127.0.0.1:6379> ZREMRANGEBYSCORE events -inf (1700000150
(integer) 2
127.0.0.1:6379> ZRANGE events 0 -1
1) "e3"
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[ZREMRANGEBYRANK](https://docs.hotkv.com/commands/zremrangebyrank/index.md), [ZREMRANGEBYLEX](https://docs.hotkv.com/commands/zremrangebylex/index.md),
[ZCOUNT](https://docs.hotkv.com/commands/zcount/index.md), [ZREM](https://docs.hotkv.com/commands/zrem/index.md)