Merge pull request #421 from cristiangreco/cristian/redis-cache-store-failsafe

Failsafe on Redis error replies in RedisCacheStoreProxy.
This commit is contained in:
Gonzalo Rodriguez 2019-07-15 18:47:17 -03:00 committed by GitHub
commit dc305e0782
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,7 @@ module Rack
# #
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize # So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
# the counter. After that we continue using the original RedisCacheStore#increment. # the counter. After that we continue using the original RedisCacheStore#increment.
rescuing do
if options[:expires_in] && !read(name) if options[:expires_in] && !read(name)
write(name, amount, options) write(name, amount, options)
@ -23,11 +24,26 @@ module Rack
super super
end end
end end
end
def read(*_args)
rescuing { super }
end
def write(name, value, options = {}) def write(name, value, options = {})
rescuing do
super(name, value, options.merge!(raw: true)) super(name, value, options.merge!(raw: true))
end end
end end
private
def rescuing
yield
rescue Redis::BaseError
nil
end
end
end end
end end
end end