未验证 提交 9f8528ac 编写于 作者: F fatkodima 提交者: Jeremy Daer

RedisCacheStore: fix `#write_multi` mset serialization

Closes #31886
Fixes #31884
上级 ee1235f1
......@@ -17,6 +17,7 @@
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 @@ def write_multi_entries(entries, expires_in: nil, **options)
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
......
......@@ -113,6 +113,16 @@ def test_fetch_multi
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!")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册