Last active
December 24, 2015 01:29
-
-
Save RickyCook/6724458 to your computer and use it in GitHub Desktop.
Really simple script to dump test data into redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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