# ZRANGEBYLEX

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

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

```
ZRANGEBYLEX key min max [LIMIT offset count]
```

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

`ZRANGEBYLEX` returns the members of the sorted set at `key` that fall between
`min` and `max` in byte-wise lexicographic order, smallest first. It is meant
for sorted sets where every member has the same score. It is the same as
`ZRANGE key min max BYLEX`; new code can use [ZRANGE](https://docs.hotkv.com/commands/zrange/index.md).

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

## Options

| Option | Effect |
| --- | --- |
| `LIMIT offset count` | Skip `offset` matching members, then return at most `count`. A negative `count` returns all remaining members. |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Success | Array of members | Same |
| Key does not exist or nothing in range | Empty array | Same |

Errors:

- `ERR min or max not valid string range item` for a bad bound.
- ``ERR syntax error, WITHSCORES not supported in combination with BYLEX`` if
  you pass `WITHSCORES`.
- `ERR syntax error` for another unknown option, and
  `ERR value is not an integer or out of range` for a non-integer `LIMIT`
  value.
- `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> ZRANGEBYLEX names [b (d
1) "bob"
2) "cat"
127.0.0.1:6379> ZRANGEBYLEX names - + LIMIT 2 5
1) "cat"
2) "dan"
```

## Compatibility

Same as Redis 7.4 and Valkey 8, where it is also deprecated in favour of
`ZRANGE ... BYLEX`.

## See also

[ZRANGE](https://docs.hotkv.com/commands/zrange/index.md), [ZREVRANGEBYLEX](https://docs.hotkv.com/commands/zrevrangebylex/index.md),
[ZLEXCOUNT](https://docs.hotkv.com/commands/zlexcount/index.md), [ZREMRANGEBYLEX](https://docs.hotkv.com/commands/zremrangebylex/index.md)