File tree Expand file tree Collapse file tree 3 files changed +26
-5
lines changed Expand file tree Collapse file tree 3 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ def self.current=(redis)
31
31
# @option options [Boolean] :inherit_socket (false) Whether to use socket in forked process or not
32
32
# @option options [Array] :sentinels List of sentinels to contact
33
33
# @option options [Symbol] :role (:master) Role to fetch via Sentinel, either `:master` or `:slave`
34
+ # @option options [Class] :connector Class of custom connector
34
35
#
35
36
# @return [Redis] a new client instance
36
37
def initialize ( options = { } )
Original file line number Diff line number Diff line change @@ -84,11 +84,14 @@ def initialize(options = {})
84
84
85
85
@pending_reads = 0
86
86
87
- if options . include? ( :sentinels )
88
- @connector = Connector ::Sentinel . new ( @options )
89
- else
90
- @connector = Connector . new ( @options )
91
- end
87
+ @connector =
88
+ if options . include? ( :sentinels )
89
+ Connector ::Sentinel . new ( @options )
90
+ elsif options . include? ( :connector ) && options [ :connector ] . respond_to? ( :new )
91
+ options . delete ( :connector ) . new ( @options )
92
+ else
93
+ Connector . new ( @options )
94
+ end
92
95
end
93
96
94
97
def connect
Original file line number Diff line number Diff line change @@ -56,4 +56,21 @@ def test_queue_after_error
56
56
57
57
assert_equal result , [ "OK" , 1 ]
58
58
end
59
+
60
+ def test_client_with_custom_connector
61
+ custom_connector = Class . new ( Redis ::Client ::Connector ) do
62
+ def resolve
63
+ @options [ :host ] = '127.0.0.5'
64
+ @options [ :port ] = '999'
65
+ @options
66
+ end
67
+ end
68
+
69
+ assert_raise_message (
70
+ 'Error connecting to Redis on 127.0.0.5:999 (Errno::ECONNREFUSED)'
71
+ ) do
72
+ new_redis = _new_client ( connector : custom_connector )
73
+ new_redis . ping
74
+ end
75
+ end
59
76
end
You can’t perform that action at this time.
0 commit comments