Skip to content

Commit cc329dc

Browse files
authored
Merge pull request rails#45762 from fatkodima/redis-delete-multi-fail-safe
Improve failure safety for `RedisCacheStore#delete_multi`
2 parents 9414a8b + b0061a3 commit cc329dc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

activesupport/lib/active_support/cache/redis_cache_store.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ def delete_entry(key, options)
388388

389389
# Deletes multiple entries in the cache. Returns the number of entries deleted.
390390
def delete_multi_entries(entries, **_options)
391-
redis.then { |c| c.del(entries) }
391+
failsafe :delete_multi_entries, returning: 0 do
392+
redis.then { |c| c.del(entries) }
393+
end
392394
end
393395

394396
# Nonstandard store provider API to write multiple values at once.

activesupport/test/cache/behaviors/failure_safety_behavior.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ def test_delete_failure_returns_false
9191
end
9292
end
9393

94+
def test_delete_multi_failure_returns_zero
95+
key = SecureRandom.uuid
96+
other_key = SecureRandom.uuid
97+
@cache.write_multi(
98+
key => SecureRandom.alphanumeric,
99+
other_key => SecureRandom.alphanumeric
100+
)
101+
102+
emulating_unavailability do |cache|
103+
assert_equal 0, cache.delete_multi([key, other_key])
104+
end
105+
end
106+
94107
def test_exist_failure_returns_false
95108
key = SecureRandom.uuid
96109
@cache.write(key, SecureRandom.alphanumeric)

0 commit comments

Comments
 (0)