Skip to content

Instantly share code, notes, and snippets.

@maurorappa
Created December 16, 2016 17:31
Show Gist options
  • Save maurorappa/d9ace294ac2a43bcce9ea485a9845b57 to your computer and use it in GitHub Desktop.
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
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