9951 explained code solutions for 126 technologies


python-redisGet all element from sorted set in Redis


r = redis.Redis()
list = r.zrange('top', 0, -1)ctrl + c
redis.Redis

connect to Redis server

zrange

retrieves sorted set elements based on offset and limit

top

name of sorted set in Redis

0, -1

will return all elements from sorted set

list

resulting list with elements from sorted set


Usage example

import redis

r = redis.Redis()

r.zadd('top', {'Donald': 2})
r.zadd('top', {'Joe': 1})

print(r.zrange('top', 0, -1))
output
[b'Joe', b'Donald']