from pprint import pprint
import redis
red = redis.Redis(*redis_host, db=db_num)
# 全データの表示
all_keys = {k.decode(): red.type(k).decode() for k in red.keys()}
for k, t in all_keys.items():
print(f'key: {k}, type: {t}')
if t == 'string':
print(red.get(k).decode())
if t == 'list':
pprint([m.decode() for m in red.lrange(k, 0, -1)])
if t == 'set':
pprint([m.decode() for m in red.smembers(k)])
if t == 'zset':
pprint([(m.decode(), red.zrank(k, m), red.zscore(k, m)) for m in red.zrange(k, 0, -1)])
if t == 'hash':
pprint([(f.decode(), v.decode()) for f, v in red.hgetall(k).items()])
print()
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme