Skip to content

Commit 83c1ed9

Browse files
fatkodimajeremy
authored andcommitted
Use Redis#mget for RedisCacheStore#fetch_multi
1 parent 3b5d940 commit 83c1ed9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

activesupport/lib/active_support/cache/redis_cache_store.rb

+8
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ def read_entry(key, options = nil)
307307
end
308308
end
309309

310+
def read_multi_entries(names, _options)
311+
if mget_capable?
312+
read_multi_mget(*names)
313+
else
314+
super
315+
end
316+
end
317+
310318
def read_multi_mget(*names)
311319
options = names.extract_options!
312320
options = merged_options(options)

activesupport/test/cache/stores/redis_cache_store_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ class RedisCacheStoreCommonBehaviorTest < StoreTest
109109
include CacheIncrementDecrementBehavior
110110
include CacheInstrumentationBehavior
111111
include AutoloadingCacheBehavior
112+
113+
def test_fetch_multi_uses_redis_mget
114+
assert_called(@cache.redis, :mget, returns: []) do
115+
@cache.fetch_multi("a", "b", "c") do |key|
116+
key * 2
117+
end
118+
end
119+
end
112120
end
113121

114122
# Separate test class so we can omit the namespace which causes expected,

0 commit comments

Comments
 (0)