Sorted Sets Zrangebylex
# Redis Zrangebylex Command
* (javascript:void(0);)
* (javascript:void(0);)
* (javascript:void(0);)
* (javascript:void(0))
Redis Tutorial
(#)(#)(#)(#)(#)
## Redis Commands
(#)(#)(#)(#)(#)(#)(#)(#)[Redis Pub/Sub](#)(#)(#)(#)(#)(#)(#)
## Advanced Redis Tutorials
(#)(#)(#)(#)(#)(#)(#)(#)
[](#)(#)
(#)[](#)
Deep Dive
Data Management
Programming
Scripting
Software
Computer Science
Search
Development Tools
Programming Languages
Web Design and Development
Web Services
# Redis Zrangebylex Command
!(#)(#)
The Redis Zrangebylex command is used to retrieve members within a specified lexicographical range from a sorted set. This command is primarily intended for sorted sets whose members are strings.
### Syntax
The basic syntax of the Redis Zrange command is as follows:
ZRANGEBYLEX key min max
* `key`: The name of the key that specifies the sorted set to be operated on.
* `min` and `max`: The boundaries of the lexicographical range. These values can be negative infinity (`-`) or positive infinity (`+`), or they can be specific string values representing the lexicographical boundaries of the members in the sorted set.
* `LIMIT offset count`: An optional parameter used to limit the number of returned results. `offset` indicates how many elements should be skipped at the beginning, while `count` specifies how many elements will be returned.
Command behavior:
* If `min` is `+` or the first element after `min`, and `max` is `-` or the last element before `max`, then all elements stored in the sorted set under the key `key` will be returned.
* If both `min` and `max` are specific strings, then all elements in the sorted set whose lexicographical order falls between `min` and `max` will be returned.
* If `min` is `+` or the first element after `min`, and `max` is a specific string, then all elements in the sorted set with a lexicographical order greater than or equal to `max` will be returned.
* If `min` is a specific string, and `max` is `-` or the last element before `max`, then all elements in the sorted set with a lexicographical order less than or equal to `min` will be returned.
### Available Versions
>= 2.8.9
### Return Value
A list of elements within the specified range.
### Example
redis 127.0.0.1:6379> ZADD myzset 0 a 0 b 0 c 0 d 0 e 0 f 0 g (integer) 7 redis 127.0.0.1:6379> ZRANGEBYLEX myzset - [c 1) "a"2) "b"3) "c" redis 127.0.0.1:6379> ZRANGEBYLEX myzset - (c 1) "a"2) "b" red
YouTip