Redis cache store: fix expanding empty keys with no namespace

This commit is contained in:
George Claghorn 2020-03-31 17:39:02 -04:00
parent a1b6f08891
commit 8c4d6a04f8
2 changed files with 8 additions and 2 deletions

View File

@ -444,11 +444,11 @@ module ActiveSupport
# Truncate keys that exceed 1kB.
def normalize_key(key, options)
truncate_key super.b
truncate_key super&.b
end
def truncate_key(key)
if key.bytesize > max_key_bytesize
if key && key.bytesize > max_key_bytesize
suffix = ":sha2:#{::Digest::SHA2.hexdigest(key)}"
truncate_at = max_key_bytesize - suffix.bytesize
"#{key.byteslice(0, truncate_at)}#{suffix}"

View File

@ -110,6 +110,12 @@ module CacheStoreBehavior
end
end
def test_read_multi_with_empty_keys_and_a_logger_and_no_namespace
@cache.options[:namespace] = nil
@cache.logger = ActiveSupport::Logger.new(nil)
assert_equal({}, @cache.read_multi)
end
def test_fetch_multi
@cache.write("foo", "bar")
@cache.write("fud", "biz")