Skip to content

Instantly share code, notes, and snippets.

@coderfi
Created March 10, 2017 07:16
Show Gist options
  • Save coderfi/d88f6337cbb45de3ad5ccdd310b1ea67 to your computer and use it in GitHub Desktop.
Save coderfi/d88f6337cbb45de3ad5ccdd310b1ea67 to your computer and use it in GitHub Desktop.
dump redis sorted set keys
#!/usr/bin/env python
''' Dumps the location ids in a sorted set '''
import redis
import sys
def dump(key, redis_host, redis_port=6379):
rconn = redis.StrictRedis(redis_host, port=redis_port)
cursor, arr = rconn.zscan(key)
for ulid, score in arr:
print ulid
while cursor != 0:
cursor, arr = rconn.zscan(key, cursor=cursor)
for ulid, score in arr:
print ulid
if __name__ == '__main__':
if len(sys.argv) != 2:
print >> sys.stderr, (
"Usage:\n"
" %s [sorted_set_key]\n"
"e.g.\n"
" %s /my_sorted_set" % (
sys.argv[0], sys.argv[0]))
sys.exit(1)
dump(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment