Skip to content

Instantly share code, notes, and snippets.

@RickyCook
Last active December 24, 2015 01:29
Show Gist options
  • Save RickyCook/6724458 to your computer and use it in GitHub Desktop.
Save RickyCook/6724458 to your computer and use it in GitHub Desktop.
Really simple script to dump test data into redis
#!/usr/bin/python
"""
REQUIREMENTS:
apt-get install python-redis
OR
pip install redis
USAGE:
./redisdump.py localhost 6380 /proc/meminfo
"""
import re
import redis
import sys
from os.path import basename
if len(sys.argv) < 4:
print "Usage: %s host port filename" % basename(sys.argv[0])
sys.exit(1)
r = redis.StrictRedis(host=sys.argv[1], port=sys.argv[2], db=0)
try:
f = open(sys.argv[3], 'r')
for line in f:
k, v = line.split(' ', 1)
k = re.sub(r'[^a-zA-Z0-9 ]', '', k)
k = k.strip()
v = v.strip()
r.set(k, v)
print "Set '%s' to '%s'" % (k, r.get(k))
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment