Skip to content

Instantly share code, notes, and snippets.

@joemiller
Created March 5, 2014 23:34
Show Gist options
  • Save joemiller/9379013 to your computer and use it in GitHub Desktop.
Save joemiller/9379013 to your computer and use it in GitHub Desktop.
redis pipe inputter for getting simple S3 key list into redis quickly
!/usr/bin/env ruby
#
# use this to bulk load s3 keys into redis.
#
# usage:
# ------
#
# cat /root/s3.keys | redis_piper.py | redis-cli -h HOST -n DB --pipe
#
def gen_redis_proto(*cmd)
proto = ""
proto << "*"+cmd.length.to_s+"\r\n"
cmd.each{|arg|
proto << "$"+arg.to_s.bytesize.to_s+"\r\n"
proto << arg.to_s+"\r\n"
}
proto
end
ARGF.each do |line|
key = line.strip
STDOUT.write(gen_redis_proto("SETNX", key, 1))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment