Created
December 16, 2016 17:31
-
-
Save maurorappa/d9ace294ac2a43bcce9ea485a9845b57 to your computer and use it in GitHub Desktop.
Turret: a small service to get notified when Redis Sentinel elects a new master
This file contains hidden or 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' | |
require 'uri' | |
uri = URI.parse('redis://127.0.0.1:26379') | |
REDIS = Redis.new(:host => uri.host, :port => uri.port) | |
REDIS.psubscribe('*switch-master' ) do |on| | |
on.psubscribe do |event, total| | |
puts "Subscribed to ##{event} (#{total} subscriptions)" | |
end | |
on.pmessage do |pattern, event, message| | |
puts "received #{message}" | |
new_master_ip = message.split[3] | |
new_master_port = message.split[3] | |
puts "master is now: #{new_master_ip}:#{new_master_port}" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment