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)
3131 # @option options [Boolean] :inherit_socket (false) Whether to use socket in forked process or not
3232 # @option options [Array] :sentinels List of sentinels to contact
3333 # @option options [Symbol] :role (:master) Role to fetch via Sentinel, either `:master` or `:slave`
34+ # @option options [Class] :connector Class of custom connector
3435 #
3536 # @return [Redis] a new client instance
3637 def initialize ( options = { } )
Original file line number Diff line number Diff line change @@ -84,11 +84,14 @@ def initialize(options = {})
8484
8585 @pending_reads = 0
8686
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
9295 end
9396
9497 def connect
Original file line number Diff line number Diff line change @@ -56,4 +56,21 @@ def test_queue_after_error
5656
5757 assert_equal result , [ "OK" , 1 ]
5858 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
5976end
You can’t perform that action at this time.
0 commit comments