diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-01-22 18:34:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-22 18:34:45 -0500 |
commit | 04edd9e819c258507ad462353dc7f06b7f2576b7 (patch) | |
tree | 3920d4c9e0e6986911fd6433ddc1006132258757 /activesupport/lib/active_support/cache/redis_cache_store.rb | |
parent | 05b7b80bcaeeb0357cdb6143fbeca1b3c73b5fb9 (diff) | |
parent | bd54991d20aa30a76815ce80912c8122a2e4ffd3 (diff) | |
download | rails-04edd9e819c258507ad462353dc7f06b7f2576b7.tar.gz rails-04edd9e819c258507ad462353dc7f06b7f2576b7.tar.bz2 rails-04edd9e819c258507ad462353dc7f06b7f2576b7.zip |
Merge pull request #31487 from fatkodima/improve_cache_fault_tolerance
Improve fault tolerance for redis cache store
Diffstat (limited to 'activesupport/lib/active_support/cache/redis_cache_store.rb')
-rw-r--r-- | activesupport/lib/active_support/cache/redis_cache_store.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/cache/redis_cache_store.rb b/activesupport/lib/active_support/cache/redis_cache_store.rb index 3347576651..c4cd9c4761 100644 --- a/activesupport/lib/active_support/cache/redis_cache_store.rb +++ b/activesupport/lib/active_support/cache/redis_cache_store.rb @@ -253,7 +253,9 @@ module ActiveSupport # Failsafe: Raises errors. def increment(name, amount = 1, options = nil) instrument :increment, name, amount: amount do - redis.with { |c| c.incrby normalize_key(name, options), amount } + failsafe :increment do + redis.with { |c| c.incrby normalize_key(name, options), amount } + end end end @@ -267,7 +269,9 @@ module ActiveSupport # Failsafe: Raises errors. def decrement(name, amount = 1, options = nil) instrument :decrement, name, amount: amount do - redis.with { |c| c.decrby normalize_key(name, options), amount } + failsafe :decrement do + redis.with { |c| c.decrby normalize_key(name, options), amount } + end end end @@ -343,7 +347,10 @@ module ActiveSupport options = merged_options(options) keys = names.map { |name| normalize_key(name, options) } - values = redis.with { |c| c.mget(*keys) } + + values = failsafe(:read_multi_mget, returning: {}) do + redis.with { |c| c.mget(*keys) } + end names.zip(values).each_with_object({}) do |(name, value), results| if value @@ -368,7 +375,7 @@ module ActiveSupport expires_in += 5.minutes end - failsafe :write_entry do + failsafe :write_entry, returning: false do if unless_exist || expires_in modifiers = {} modifiers[:nx] = unless_exist |