Created
October 10, 2011 23:41
-
-
Save santosh79/1276880 to your computer and use it in GitHub Desktop.
Ruby Script for parsing and loading redis AOF file
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
require 'rubygems' | |
require 'redis' | |
aof_file = ARGV[0] | |
p "reading aof_file: #{aof_file}" | |
file = File.read aof_file | |
$server = { | |
"host" => "localhost", | |
"port" => 6379 | |
} | |
redis_cnxn = Redis.new $server | |
redis_cnxn.flushall | |
puts "file has #{file.split("\r\n").size} lines" | |
commands = file.split /^\*/ | |
commands.each do |cmd| | |
split_cmd = cmd.split("\r\n")[1..-1] | |
next unless split_cmd | |
split_cmd.reject! { |cmd| cmd =~ /^\$/ } | |
redis_cmd = split_cmd[0] | |
redis_key = split_cmd[1] | |
redis_args = split_cmd[2..-1] | |
p "command: #{redis_cmd} \t key: #{redis_key} and args: #{redis_args}" | |
p "copying key: #{redis_key} to server: #{$servers[idx].inspect}" | |
redis_cnxn.send redis_cmd, redis_key, *redis_args | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment