Redis: Return All Values Stored In A Database
We're using Redis to store various application configurations in a DB 0. Is it possible to query Redis for every key/valuie pair within the database, without having to perform two
Solution 1:
There are differences between different types in Redis, so you have to look at the data type to determine how to get the values from the key. So:
keys = redis.keys('*')
for key in keys:
type = redis.type(key)
if type == "string":
val = redis.get(key)
if type == "hash":
vals = redis.hgetall(key)
if type == "zset":
vals = redis.zrange(key, 0, -1)
if type == "list":
vals = redis.lrange(key, 0, -1)
if type == "set":
vals = redis. smembers(key)
Post a Comment for "Redis: Return All Values Stored In A Database"