File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -158,8 +158,11 @@ def build_redis_client(**redis_options)
158
158
# cache.exist?('bar') # => false
159
159
def initialize ( error_handler : DEFAULT_ERROR_HANDLER , **redis_options )
160
160
universal_options = redis_options . extract! ( *UNIVERSAL_OPTIONS )
161
+ redis = redis_options [ :redis ]
162
+
163
+ already_pool = redis . instance_of? ( ::ConnectionPool ) ||
164
+ ( redis . respond_to? ( :wrapped_pool ) && redis . wrapped_pool . instance_of? ( ::ConnectionPool ) )
161
165
162
- already_pool = redis_options [ :redis ] . instance_of? ( ::ConnectionPool )
163
166
if !already_pool && pool_options = self . class . send ( :retrieve_pool_options , redis_options )
164
167
@redis = ::ConnectionPool . new ( pool_options ) { self . class . build_redis ( **redis_options ) }
165
168
else
Original file line number Diff line number Diff line change @@ -328,7 +328,7 @@ def test_connection_pooling_by_default
328
328
assert_equal 5 , pool . instance_variable_get ( :@timeout )
329
329
end
330
330
331
- def test_no_connection_pooling_by_default_when_already_pool
331
+ def test_no_connection_pooling_by_default_when_already_a_pool
332
332
redis = ::ConnectionPool . new ( size : 10 , timeout : 2.5 ) { Redis . new }
333
333
cache = ActiveSupport ::Cache . lookup_store ( :redis_cache_store , redis : redis )
334
334
pool = cache . redis
@@ -338,6 +338,18 @@ def test_no_connection_pooling_by_default_when_already_pool
338
338
assert_equal 2.5 , pool . instance_variable_get ( :@timeout )
339
339
end
340
340
341
+ def test_no_connection_pooling_by_default_when_already_wrapped_in_a_pool
342
+ redis = ::ConnectionPool ::Wrapper . new ( size : 10 , timeout : 2.5 ) { Redis . new }
343
+ cache = ActiveSupport ::Cache . lookup_store ( :redis_cache_store , redis : redis )
344
+ wrapped_redis = cache . redis
345
+ assert_kind_of ::Redis , wrapped_redis
346
+ assert_same redis , wrapped_redis
347
+ pool = wrapped_redis . wrapped_pool
348
+ assert_kind_of ::ConnectionPool , pool
349
+ assert_equal 10 , pool . size
350
+ assert_equal 2.5 , pool . instance_variable_get ( :@timeout )
351
+ end
352
+
341
353
private
342
354
def store
343
355
[ :redis_cache_store ]
You can’t perform that action at this time.
0 commit comments