Skip to content

Instantly share code, notes, and snippets.

@barryperez
Created November 16, 2016 15:49
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 barryperez/b1674b0c0cc198d65735d2f64fe68900 to your computer and use it in GitHub Desktop.
Save barryperez/b1674b0c0cc198d65735d2f64fe68900 to your computer and use it in GitHub Desktop.
Simple Python script to take a file and generate Redis protocol
#!/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))
@barryperez
Copy link
Author

List name used is the name of the file.

Usage:

generate_redis.py [FILENAME] | redis-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment