Created
January 4, 2012 18:18
-
-
Save antirez/1561301 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'json' | |
require 'redis' | |
def protocol(file,args) | |
bytes = "*#{args.length}\r\n" | |
args.each{|a| | |
bytes << "$#{a.to_s.length}\r\n#{a}\r\n" | |
} | |
file.write(bytes) | |
end | |
def exec(filename) | |
puts filename | |
r = Redis.new | |
dst = File.open(filename+".aof","w") | |
File.open(filename).each_line{|l| | |
s = l.split(" ") | |
cmd = s[1] | |
o = JSON.parse(s[2..-1].join(" ")) | |
case cmd | |
when "zadd" | |
# puts "zadd #{o["key"]} #{o["score"]} #{o["member"]}" | |
protocol(dst,["zadd",o["key"],o["score"],o["member"]]) | |
when "zrem" | |
protocol(dst,["zrem",o["key"],o["member"]]) | |
when "zcard" | |
protocol(dst,["zcard",o["key"]]) | |
when "zrevrange" | |
protocol(dst,["zrevrange",o["key"],o["start"],o["stop"]]) | |
when "zrevrank" | |
protocol(dst,["zrevrank",o["key"],o["member"]]) | |
else | |
puts "Not handled: #{cmd}" | |
end | |
} | |
end | |
ARGV.each{|x| | |
exec x | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example entry:
[1324046700672] zadd {"key":"keyname","score":166768,"member":169986036,"err":"Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED"}