antirez/redis — Issue #165: Modify SMEMBERS behavior when the client is a Lua script
Author: antirez
Created: 2011-10-27 14:16:19+00:00
State: open
Labels: non critical bug

Currently SMEMBERS will return members in a random order, since sets are unordered by default.
This is a problem in the context of scripting as this introduces a point of non determinism, for instance I can do a script getting all the elements from a Set, then pushing that elements into a List with RPUSH.

But if the order of returned elements changes, the result will also change.

The simplest solution is translating `SMEMBERS ` into `SORT ALPHA` when the client is the Lua.
The commands have the same output exactly if not for that difference:

redis 127.0.0.1:6379> sadd foo a b c d e f g h i
(integer) 9

```
redis 127.0.0.1:6379> smembers foo
1) "c"
2) "d"
3) "e"
4) "f"
5) "g"
6) "h"
7) "i"
8) "a"
9) "b"

redis 127.0.0.1:6379> sort foo alpha
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
6) "f"
7) "g"
8) "h"
9) "i"
```