Skip to content

Instantly share code, notes, and snippets.

@tdooner
Created August 29, 2014 21:23
Show Gist options
  • Save tdooner/e7db6124796ae2239479 to your computer and use it in GitHub Desktop.
Save tdooner/e7db6124796ae2239479 to your computer and use it in GitHub Desktop.
Redis Sentinel Failover Testing Script
require 'redis'
require 'redis-sentinel'
require 'timeout'
require 'logger'
class TestClient
def initialize
@sentinels = [
{ host: 'sentinel01.example.com', port: 26379 },
{ host: 'sentinel02.example.com', port: 26379 },
{ host: 'sentinel03.example.com', port: 26379 },
]
@redis = Redis.new(
master_name: 'your-master-name',
sentinels: @sentinels,
failover_reconnect_timeout: 60,
logger: Logger.new(STDOUT)
)
end
def test_connection
input = Random.rand(10_000_000)
output = nil
@redis.set('foo', input)
Timeout.timeout(0.1) do
output = @redis.get('foo').to_i
end
return "ERROR: Incorrect response #{input} != #{output}" unless input == output
return "Success (#{input} == #{output}) from #{@redis.id}"
rescue Timeout::Error
return 'ERROR: Timeout exceeded'
end
end
test = TestClient.new
while true
puts test.test_connection
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment