diff --git a/lib/async/redis/sentinel_client.rb b/lib/async/redis/sentinel_client.rb index befd4ca..de939ac 100644 --- a/lib/async/redis/sentinel_client.rb +++ b/lib/async/redis/sentinel_client.rb @@ -20,13 +20,16 @@ class SentinelClient # # @property endpoints [Array(Endpoint)] The list of sentinel endpoints. # @property master_name [String] The name of the master instance, defaults to 'mymaster'. + # @property master_options [Hash] Connection options for master. # @property role [Symbol] The role of the instance that you want to connect to, either `:master` or `:slave`. - # @property protocol [Protocol] The protocol to use when connecting to the actual Redis server, defaults to {Protocol::RESP2}. - def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, role: :master, protocol: Protocol::RESP2, **options) + def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, master_options: nil, role: :master, **options) @endpoints = endpoints @master_name = master_name + @master_options = master_options || {} @role = role - @protocol = protocol + + @ssl = !!master_options&.key?(:ssl_context) + @scheme = "redis#{@ssl ? 's' : ''}" # A cache of sentinel connections. @sentinels = {} @@ -88,8 +91,8 @@ def resolve_master rescue Errno::ECONNREFUSED next end - - return Endpoint.remote(address[0], address[1]) if address + + return Endpoint.for(@scheme, address[0], port: address[1], **@master_options) if address end return nil @@ -107,7 +110,7 @@ def resolve_slave next if slaves.empty? slave = select_slave(slaves) - return Endpoint.remote(slave["ip"], slave["port"]) + return Endpoint.for(@scheme, slave["ip"], port: slave["port"], **@master_options) end return nil @@ -116,7 +119,6 @@ def resolve_slave protected def assign_default_tags(tags) - tags[:protocol] = @protocol.to_s end # Override the parent method. The only difference is that this one needs to resolve the master/slave address. @@ -127,8 +129,8 @@ def make_pool(**options) endpoint = resolve_address peer = endpoint.connect stream = ::IO::Stream(peer) - - @protocol.client(stream) + + endpoint.protocol.client(stream) end end