diff options
author | fatkodima <fatkodima123@gmail.com> | 2018-02-05 00:35:17 +0200 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2018-02-04 17:16:27 -0800 |
commit | 08aa8afd24e65525757c6cb9ef2af60b5984c6ac (patch) | |
tree | f3b15dc88afe2ac6398004994604d10e5c35007d /activesupport | |
parent | 5d1999547d81edb07c0ce9149023b1bcd5de8a57 (diff) | |
download | rails-08aa8afd24e65525757c6cb9ef2af60b5984c6ac.tar.gz rails-08aa8afd24e65525757c6cb9ef2af60b5984c6ac.tar.bz2 rails-08aa8afd24e65525757c6cb9ef2af60b5984c6ac.zip |
RedisCacheStore: fix `#write_multi` mset serialization
Closes #31886
Fixes #31884
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/cache/redis_cache_store.rb | 9 | ||||
-rw-r--r-- | activesupport/test/cache/behaviors/cache_store_behavior.rb | 10 |
2 files changed, 18 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/cache/redis_cache_store.rb b/activesupport/lib/active_support/cache/redis_cache_store.rb index 1de98dcd6c..b5a2a2a636 100644 --- a/activesupport/lib/active_support/cache/redis_cache_store.rb +++ b/activesupport/lib/active_support/cache/redis_cache_store.rb @@ -17,6 +17,7 @@ end require "digest/sha2" require "active_support/core_ext/marshal" +require "active_support/core_ext/hash/transform_values" module ActiveSupport module Cache @@ -360,7 +361,13 @@ module ActiveSupport if entries.any? if mset_capable? && expires_in.nil? failsafe :write_multi_entries do - redis.mapped_mset(entries) + serialized_entries = if options[:raw] + entries.transform_values { |e| e.value.to_s } + else + entries.transform_values { |e| serialize_entry(e) } + end + + redis.mapped_mset(serialized_entries) end else super diff --git a/activesupport/test/cache/behaviors/cache_store_behavior.rb b/activesupport/test/cache/behaviors/cache_store_behavior.rb index ac37ab6e61..efb57d34a2 100644 --- a/activesupport/test/cache/behaviors/cache_store_behavior.rb +++ b/activesupport/test/cache/behaviors/cache_store_behavior.rb @@ -113,6 +113,16 @@ module CacheStoreBehavior assert_equal("fufu", @cache.read("fu")) end + def test_fetch_multi_without_expires_in + @cache.write("foo", "bar") + @cache.write("fud", "biz") + + values = @cache.fetch_multi("foo", "fu", "fud", expires_in: nil) { |value| value * 2 } + + assert_equal({ "foo" => "bar", "fu" => "fufu", "fud" => "biz" }, values) + assert_equal("fufu", @cache.read("fu")) + end + def test_multi_with_objects cache_struct = Struct.new(:cache_key, :title) foo = cache_struct.new("foo", "FOO!") |