Skip to content

Instantly share code, notes, and snippets.

@wangchen
Last active July 29, 2016 09:24
Show Gist options
  • Save wangchen/54108e3b86bd3d191738a33e8c27ee14 to your computer and use it in GitHub Desktop.
Save wangchen/54108e3b86bd3d191738a33e8c27ee14 to your computer and use it in GitHub Desktop.
Print size of all redis keys
import redis
r = redis.Redis()
i = 0
chunk_size = 1000
while True:
i, keys = r.scan(i, count=chunk_size)
if i == 0:
break
pipeline = r.pipeline()
for key in keys:
pipeline.debug_object(key)
vals = pipeline.execute()
for k, v in zip(keys, vals):
print("%s\t%s" % (k.decode(), v['serializedlength']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment