Skip to content

Instantly share code, notes, and snippets.

@antirez
Created January 4, 2012 18:18
Show Gist options
  • Save antirez/1561301 to your computer and use it in GitHub Desktop.
Save antirez/1561301 to your computer and use it in GitHub Desktop.
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
}
@antirez
Copy link
Author

antirez commented Jan 4, 2012

Example entry:

[1324046700672] zadd {"key":"keyname","score":166768,"member":169986036,"err":"Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED"}

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