Created
November 16, 2016 15:49
-
-
Save barryperez/b1674b0c0cc198d65735d2f64fe68900 to your computer and use it in GitHub Desktop.
Simple Python script to take a file and generate Redis protocol
This file contains 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/env python | |
import sys | |
def gen_redis_proto(*args): | |
proto = '' | |
proto += '*' + str(len(args)) + '\r\n' | |
for arg in args: | |
proto += '$' + str(len(arg)) + '\r\n' | |
proto += str(arg) + '\r\n' | |
return proto | |
with open(sys.argv[1]) as data_file: | |
for line in data_file: | |
sys.stdout.write(gen_redis_proto("LPUSH", sys.argv[1], line)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
List name used is the name of the file.
Usage:
generate_redis.py [FILENAME] | redis-cli