class Redic

Public Instance Methods

establish_connection() click to toggle source
# File lib/redic/sentinels.rb, line 84
def establish_connection
  hosts.each do |host|
    begin
      sentinel = Redic.new "redis://#{host}"

      ip, port = sentinel.call 'SENTINEL', 'get-master-addr-by-name', master_name
      raise UnknownMaster if ip.nil? && port.nil?

      @redis = Redic.new *["redis://#{password ? ":#{password}@" : ''}#{ip}:#{port}/#{db}", timeout].compact
      return

    rescue Errno::ECONNREFUSED
    end
  end

  raise UnreachableHosts
end