Reputation: 583
When I try to get members of a set using python smembers function it is always returning shuffled data. And every call to smembers returns random data. However when I do a smembers through redis cli, it always returns correct sorted data from that set.
print(redis_con.smembers('alpha'))
Upvotes: 0
Views: 594
Reputation: 22946
Redis set is unordered, so the result of smembers
are NOT sorted. That's a expected behavior. If you want to have sorted result, you need to sort it manually.
Upvotes: 0
Reputation: 18106
redis-py
returns a Python set which is per default unordered:
>>> import redis
>>> con = redis.Redis('localhost', 6666)
>>> rSet = con.smembers('xyz')
>>> print(type(rSet))
<class 'set'>
You would need to sort the set yourself:
rSetSorted = sorted(rSet)
Upvotes: 1