Friday, 28 October 2016

Redis downtime when upgrating an instance

redis = Redis.new(:url => 'redis://localhost:6379/1')
disconnected_at = nil
loop do
begin
if disconnected_at && (size = redis.keys('testing:*').count)
puts "reconnected_at #{Time.now}"
puts "KeysSize: #{size}"
break
end
redis.set("testing:#{Time.now.to_i}", 1)
puts "#{Time.now}=>#{redis.keys('testing:*').count}"
sleep 2
rescue Redis::CannotConnectError, Errno::EINVAL
unless disconnected_at
disconnected_at = Time.now
puts "disconnected_at #{disconnected_at}"
end
retry
end
end

No comments:

Post a Comment