Skip to content

Instantly share code, notes, and snippets.

@steinnes
Created April 1, 2014 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steinnes/9917764 to your computer and use it in GitHub Desktop.
Save steinnes/9917764 to your computer and use it in GitHub Desktop.
Because "keys *" can block for several seconds (or longer) on large redis instances, this script scans through keys and dumps them safely. Suffers from the standard SCAN limitations, so it actually may never finish.
import redis
import sys
port = None
try:
port = int(sys.argv[2])
except:
pass
r = redis.Redis(sys.argv[1], port)
cursor = "0"
while True:
cursor, keys = r.scan(cursor)
for k in keys:
print k
if cursor == "0":
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment