Created
March 5, 2014 23:34
-
-
Save joemiller/9379013 to your computer and use it in GitHub Desktop.
redis pipe inputter for getting simple S3 key list into redis quickly
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 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