From 67bace2afc5884c6c3273251ae6e29e4fb26d82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Lled=C3=B3?= Date: Wed, 4 Jun 2025 17:44:54 +0200 Subject: [PATCH 1/3] Sentinels: Accept options to connect to master --- lib/async/redis/sentinel_client.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/async/redis/sentinel_client.rb b/lib/async/redis/sentinel_client.rb index 020414f..569af45 100644 --- a/lib/async/redis/sentinel_client.rb +++ b/lib/async/redis/sentinel_client.rb @@ -21,13 +21,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 = {} @@ -103,8 +106,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 @@ -124,7 +127,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 @@ -133,7 +136,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. @@ -144,8 +146,8 @@ def make_pool(**options) endpoint = resolve_address peer = endpoint.connect stream = ::IO::Stream(peer) - - @protocol.client(stream) + + endpoint.protocol.client(stream) end end From d7e204da90aa52e937aafa9feac7b1928addbbff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Lled=C3=B3?= Date: Thu, 5 Jun 2025 17:00:03 +0200 Subject: [PATCH 2/3] Handle empty master options --- lib/async/redis/sentinel_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/async/redis/sentinel_client.rb b/lib/async/redis/sentinel_client.rb index 569af45..80ec233 100644 --- a/lib/async/redis/sentinel_client.rb +++ b/lib/async/redis/sentinel_client.rb @@ -26,7 +26,7 @@ class SentinelClient def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, master_options: nil, role: :master, **options) @endpoints = endpoints @master_name = master_name - @master_options = master_options + @master_options = master_options || {} @role = role @ssl = !!master_options&.key?(:ssl_context) From bb693e84039afa174dddb65013228ca6068390b4 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 29 Jun 2025 01:22:19 +0900 Subject: [PATCH 3/3] Update lib/async/redis/sentinel_client.rb Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/async/redis/sentinel_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/async/redis/sentinel_client.rb b/lib/async/redis/sentinel_client.rb index 80ec233..ecb4b9a 100644 --- a/lib/async/redis/sentinel_client.rb +++ b/lib/async/redis/sentinel_client.rb @@ -29,7 +29,7 @@ def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, master_options: nil, @master_options = master_options || {} @role = role - @ssl = !!master_options&.key?(:ssl_context) + @ssl = !!@master_options.key?(:ssl_context) @scheme = "redis#{@ssl ? 's' : ''}" # A cache of sentinel connections.