diff --git a/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb b/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb index 78807f8..f4081be 100644 --- a/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb +++ b/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb @@ -15,17 +15,33 @@ module Rack # # 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. - if options[:expires_in] && !read(name) - write(name, amount, options) + rescuing do + if options[:expires_in] && !read(name) + write(name, amount, options) - amount - else - super + amount + else + super + end end end + def read(*_args) + rescuing { super } + end + def write(name, value, options = {}) - super(name, value, options.merge!(raw: true)) + rescuing do + super(name, value, options.merge!(raw: true)) + end + end + + private + + def rescuing + yield + rescue Redis::BaseError + nil end end end