Skip to content

Instantly share code, notes, and snippets.

@atsuoishimoto
Last active April 30, 2023 04:46
Show Gist options
  • Save atsuoishimoto/75385cebf600bcf9283efc7ae9c348e5 to your computer and use it in GitHub Desktop.
Save atsuoishimoto/75385cebf600bcf9283efc7ae9c348e5 to your computer and use it in GitHub Desktop.
import pprint
import redis
def get_key(db, key):
type = db.type(key)
if type == 'list':
return db.lrange(key, 0, -1)
elif type == 'hash':
return db.hgetall(key)
elif type == 'set':
return db.smembers(key)
elif type == 'zset':
return db.zrange(key, 0, -1)
else:
return db.get(key)
def to_dict(db):
keys = db.keys("*")
all = []
for key in keys:
all.append((key, get_key(db, key)))
return dict(all)
def printall(host="localhost", port=6379, db=0):
redisdb = redis.StrictRedis(host=host, port=port, db=db, decode_responses=True)
d = to_dict(redisdb)
pprint.pprint(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment