ZRANGEBYLEX key min max [LIMIT offset count]

    Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).

    When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at with a value between min and max.

    If the elements in the sorted set have different scores, the returned elements are unspecified.

    The elements are considered to be ordered from lower to higher strings as compared byte-by-byte using the memcmp() C function. Longer strings are considered greater than shorter strings if the common part is identical.

    Valid start and stop must start with ( or [, in order to specify if the range item is respectively exclusive or inclusive. The special values of + or for start and stop have the special meaning or positively infinite and negatively infinite strings, so for instance the command ZRANGEBYLEX myzset - + is guaranteed to return all the elements in the sorted set, if all the elements have the same score.

    Strings are compared as binary array of bytes. Because of how the ASCII character set is specified, this means that usually this also have the effect of comparing normal ASCII characters in an obvious dictionary way. However this is not true if non plain ASCII strings are used (for example utf8 strings).

    However the user can apply a transformation to the encoded string so that the first part of the element inserted in the sorted set will compare as the user requires for the specific application. For example if I want to add strings that will be compared in a case-insensitive way, but I still want to retrieve the real case when querying, I can add strings in the following way:

    Because of the first normalized part in every element (before the colon character), we are forcing a given comparison, however after the range is queries using the application can display to the user the second part of the string, after the colon.

    Array reply: list of elements in the specified score range.

    redis> ZADD myzset 0 a 0 b 0 c 0 d 0 e 0 f 0 g

    redis> ZRANGEBYLEX myzset - [c

    redis> ZRANGEBYLEX myzset - (c

    redis>