jamesls/fakeredis — pull request #56 by Grokzen (2014-06-17 00:13:31+00:00)
Title: desc should be used before slizing result in sort()

When running the following code it outputs wrong data

``` python
>>> from fakeredis import FakeStrictRedis
>>> f = FakeStrictRedis()
>>> f.rpush("foo", "2", "3", "4")
3
>>> f.sort("foo")
['2', '3', '4']
>>> f.sort("1", start=0, num=1)
['2'] # Correct
>>> f.sort("1", start=0, num=1, desc=True)
['2'] # Wrong
```

It should reverse the sorted data before slizing. This is how redis-cli handles the same case

```
127.0.0.1:6379> rpush foo 1 2 3 4 5
(integer) 5
127.0.0.1:6379> lrange foo 0 -1
1) "1"
2) "2"
3) "3"
4) "4"
5) "5"
127.0.0.1:6379> sort foo
1) "1"
2) "2"
3) "3"
4) "4"
5) "5"
127.0.0.1:6379> sort foo DESC
1) "5"
2) "4"
3) "3"
4) "2"
5) "1"
127.0.0.1:6379> sort foo LIMIT 0 1
1) "1"
127.0.0.1:6379> sort foo LIMIT 0 1 DESC
1) "5"
127.0.0.1:6379>
```