Skip to content

Commit 91ba198

Browse files
committed
Sentinels: Accept options to connect to master
1 parent e126f6c commit 91ba198

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/async/redis/sentinel_client.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ class SentinelClient
2020
#
2121
# @property endpoints [Array(Endpoint)] The list of sentinel endpoints.
2222
# @property master_name [String] The name of the master instance, defaults to 'mymaster'.
23+
# @property master_options [Hash] Connection options for master.
2324
# @property role [Symbol] The role of the instance that you want to connect to, either `:master` or `:slave`.
24-
# @property protocol [Protocol] The protocol to use when connecting to the actual Redis server, defaults to {Protocol::RESP2}.
25-
def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, role: :master, protocol: Protocol::RESP2, **options)
25+
def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, master_options: nil, role: :master, **options)
2626
@endpoints = endpoints
2727
@master_name = master_name
28+
@master_options = master_options
2829
@role = role
29-
@protocol = protocol
30+
31+
@ssl = !!master_options&.key?(:ssl_context)
32+
@scheme = "redis#{@ssl ? 's' : ''}"
3033

3134
# A cache of sentinel connections.
3235
@sentinels = {}
@@ -88,8 +91,8 @@ def resolve_master
8891
rescue Errno::ECONNREFUSED
8992
next
9093
end
91-
92-
return Endpoint.remote(address[0], address[1]) if address
94+
95+
return Endpoint.for(@scheme, address[0], port: address[1], **@master_options) if address
9396
end
9497

9598
return nil
@@ -107,7 +110,7 @@ def resolve_slave
107110
next if slaves.empty?
108111

109112
slave = select_slave(slaves)
110-
return Endpoint.remote(slave["ip"], slave["port"])
113+
return Endpoint.for(@scheme, slave["ip"], port: slave["port"], **@master_options)
111114
end
112115

113116
return nil
@@ -116,7 +119,6 @@ def resolve_slave
116119
protected
117120

118121
def assign_default_tags(tags)
119-
tags[:protocol] = @protocol.to_s
120122
end
121123

122124
# 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)
127129
endpoint = resolve_address
128130
peer = endpoint.connect
129131
stream = ::IO::Stream(peer)
130-
131-
@protocol.client(stream)
132+
133+
endpoint.protocol.client(stream)
132134
end
133135
end
134136

0 commit comments

Comments
 (0)