Skip to content

Instantly share code, notes, and snippets.

@msroot
Created October 29, 2016 01:22
Show Gist options
  • Save msroot/ea23b3ac8ffc1d4663cfaed28de36b1b to your computer and use it in GitHub Desktop.
Save msroot/ea23b3ac8ffc1d4663cfaed28de36b1b to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment