# ZREMRANGEBYLEX

> Remove the members of a sorted set in a lexicographic range.

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

```
ZREMRANGEBYLEX 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

`ZREMRANGEBYLEX` removes the members of the sorted set at `key` that fall
between `min` and `max` in byte-wise lexicographic order. It is meant for
sorted sets where every member has the same score. When the sorted set becomes
empty, the key is deleted.

Each bound must be `[value` (inclusive), `(value` (exclusive), `-` (lowest
possible) or `+` (highest possible).

## 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 not valid string range item` 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 names 0 "ann" 0 "bob" 0 "cat" 0 "dan"
(integer) 4
127.0.0.1:6379> ZREMRANGEBYLEX names [b [c
(integer) 1
127.0.0.1:6379> ZREMRANGEBYLEX names [b [cz
(integer) 1
127.0.0.1:6379> ZRANGE names 0 -1
1) "ann"
2) "dan"
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[ZRANGEBYLEX](https://docs.hotkv.com/commands/zrangebylex/index.md), [ZLEXCOUNT](https://docs.hotkv.com/commands/zlexcount/index.md),
[ZREMRANGEBYSCORE](https://docs.hotkv.com/commands/zremrangebyscore/index.md)