mirror of https://github.com/rails/rails
Improve failure safety for `RedisCacheStore#delete_multi`
For redis cache store, running `Rails.cache.delete_multi(["foo", "bar"])` will lead to an error when redis is down. Other existing cache store methods already implement failure safety.
This commit is contained in:
parent
0c9e4069f7
commit
b0061a30a0
|
@ -388,7 +388,9 @@ module ActiveSupport
|
|||
|
||||
# Deletes multiple entries in the cache. Returns the number of entries deleted.
|
||||
def delete_multi_entries(entries, **_options)
|
||||
redis.then { |c| c.del(entries) }
|
||||
failsafe :delete_multi_entries, returning: 0 do
|
||||
redis.then { |c| c.del(entries) }
|
||||
end
|
||||
end
|
||||
|
||||
# Nonstandard store provider API to write multiple values at once.
|
||||
|
|
|
@ -91,6 +91,19 @@ module FailureSafetyBehavior
|
|||
end
|
||||
end
|
||||
|
||||
def test_delete_multi_failure_returns_zero
|
||||
key = SecureRandom.uuid
|
||||
other_key = SecureRandom.uuid
|
||||
@cache.write_multi(
|
||||
key => SecureRandom.alphanumeric,
|
||||
other_key => SecureRandom.alphanumeric
|
||||
)
|
||||
|
||||
emulating_unavailability do |cache|
|
||||
assert_equal 0, cache.delete_multi([key, other_key])
|
||||
end
|
||||
end
|
||||
|
||||
def test_exist_failure_returns_false
|
||||
key = SecureRandom.uuid
|
||||
@cache.write(key, SecureRandom.alphanumeric)
|
||||
|
|
Loading…
Reference in New Issue