Last active
April 30, 2023 04:46
-
-
Save atsuoishimoto/75385cebf600bcf9283efc7ae9c348e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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