@@ -21,13 +21,16 @@ class SentinelClient
21
21
#
22
22
# @property endpoints [Array(Endpoint)] The list of sentinel endpoints.
23
23
# @property master_name [String] The name of the master instance, defaults to 'mymaster'.
24
+ # @property master_options [Hash] Connection options for master.
24
25
# @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 )
27
27
@endpoints = endpoints
28
28
@master_name = master_name
29
+ @master_options = master_options
29
30
@role = role
30
- @protocol = protocol
31
+
32
+ @ssl = !!master_options &.key? ( :ssl_context )
33
+ @scheme = "redis#{ @ssl ? 's' : '' } "
31
34
32
35
# A cache of sentinel connections.
33
36
@sentinels = { }
@@ -103,8 +106,8 @@ def resolve_master
103
106
rescue Errno ::ECONNREFUSED
104
107
next
105
108
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
108
111
end
109
112
110
113
return nil
@@ -124,7 +127,7 @@ def resolve_slave
124
127
next if slaves . empty?
125
128
126
129
slave = select_slave ( slaves )
127
- return Endpoint . remote ( slave [ "ip" ] , slave [ "port" ] )
130
+ return Endpoint . for ( @scheme , slave [ "ip" ] , port : slave [ "port" ] , ** @master_options )
128
131
end
129
132
130
133
return nil
@@ -133,7 +136,6 @@ def resolve_slave
133
136
protected
134
137
135
138
def assign_default_tags ( tags )
136
- tags [ :protocol ] = @protocol . to_s
137
139
end
138
140
139
141
# 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)
144
146
endpoint = resolve_address
145
147
peer = endpoint . connect
146
148
stream = ::IO ::Stream ( peer )
147
-
148
- @ protocol. client ( stream )
149
+
150
+ endpoint . protocol . client ( stream )
149
151
end
150
152
end
151
153
0 commit comments