antirez/redis — Issue #324: ZRANGEBYLEX -- get lexicographic ranges from sorted sets
Author: antirez
Created: 2012-02-03 16:32:02+00:00
State: open
Labels: approved feature, feature request, more design needed, waiting user input

ZRANGEBYLEX key min max [WITHSCORES] [LIMIT ...] [NOCASE]

How it works... To start the most important thing:

> ZRANGEBYLEX zset (aaa (bbb
-ERR Not all the elements in the sorted set have the same score.

So this is the requisite of the command, and it can do a super fast
check about this indeed, just check the first and last element of the
skiplist, and check if the score is equal.
Now assuming they are equal, what the command does is trivial, it
returns all the elements in the specified range, unless LIMIT is
specified of course.

Now how ranges are specified? I'm cloning your range structure, as
'zrangelexspec', but form the user point of view this is how it works:

The first character of the min or max specify if it is an open, closed
interval, or a string infinity or a string minus infinity:

```
"(foo" -> "foo" open interval
"[foo" -> "foo" closed interval
"-" -> the smallest string possible
"+" -> the biggest string possible
```

So for instance ZRANGEBYLEX zset - + will just return everything, and so forth.

Of course:

> ZRANGEBYLEX zset foo bar
-ERR Syntax error

> ZRANGEBYLEX zset (foo +bar
-ERR Syntax error