Skip to content

Instantly share code, notes, and snippets.

@abecciu
Created November 19, 2010 20:34
Show Gist options
  • Save abecciu/707118 to your computer and use it in GitHub Desktop.
Save abecciu/707118 to your computer and use it in GitHub Desktop.
run bgrewriteaof without blocking redis
#!/usr/bin/env ruby
require 'rubygems'
require 'redis'
r = Redis.new(:timeout => 1)
append_fsync_val = r.config(:get, 'appendfsync').values.first
puts "Disabling appendfsync..."
r.config(:set, 'appendfsync', 'no')
begin
puts "Running BGREWRITEAOF..."
r.bgrewriteaof
loop do
begin
break if r.info["bgrewriteaof_in_progress"] == "0"
sleep 1
rescue Errno::EAGAIN => e
true
end
end
ensure
puts "Enabling appendfsync..."
r.config(:set, 'appendfsync', append_fsync_val)
end
puts "Done!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment