Skip to content

Commit 67bace2

Browse files
jlledomioquatix
authored andcommitted
Sentinels: Accept options to connect to master
1 parent a2235e3 commit 67bace2

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
@@ -21,13 +21,16 @@ class SentinelClient
2121
#
2222
# @property endpoints [Array(Endpoint)] The list of sentinel endpoints.
2323
# @property master_name [String] The name of the master instance, defaults to 'mymaster'.
24+
# @property master_options [Hash] Connection options for master.
2425
# @property role [Symbol] The role of the instance that you want to connect to, either `:master` or `:slave`.
25-
# @property protocol [Protocol] The protocol to use when connecting to the actual Redis server, defaults to {Protocol::RESP2}.
26-
def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, role: :master, protocol: Protocol::RESP2, **options)
26+
def initialize(endpoints, master_name: DEFAULT_MASTER_NAME, master_options: nil, role: :master, **options)
2727
@endpoints = endpoints
2828
@master_name = master_name
29+
@master_options = master_options
2930
@role = role
30-
@protocol = protocol
31+
32+
@ssl = !!master_options&.key?(:ssl_context)
33+
@scheme = "redis#{@ssl ? 's' : ''}"
3134

3235
# A cache of sentinel connections.
3336
@sentinels = {}
@@ -103,8 +106,8 @@ def resolve_master
103106
rescue Errno::ECONNREFUSED
104107
next
105108
end
106-
107-
return Endpoint.remote(address[0], address[1]) if address
109+
110+
return Endpoint.for(@scheme, address[0], port: address[1], **@master_options) if address
108111
end
109112

110113
return nil
@@ -124,7 +127,7 @@ def resolve_slave
124127
next if slaves.empty?
125128

126129
slave = select_slave(slaves)
127-
return Endpoint.remote(slave["ip"], slave["port"])
130+
return Endpoint.for(@scheme, slave["ip"], port: slave["port"], **@master_options)
128131
end
129132

130133
return nil
@@ -133,7 +136,6 @@ def resolve_slave
133136
protected
134137

135138
def assign_default_tags(tags)
136-
tags[:protocol] = @protocol.to_s
137139
end
138140

139141
# 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)
144146
endpoint = resolve_address
145147
peer = endpoint.connect
146148
stream = ::IO::Stream(peer)
147-
148-
@protocol.client(stream)
149+
150+
endpoint.protocol.client(stream)
149151
end
150152
end
151153

0 commit comments

Comments
 (0)