From 2fac6418f88d5128faf14a1121e253de99d3c05b Mon Sep 17 00:00:00 2001 From: fatkodima Date: Mon, 14 Oct 2019 23:16:52 +0300 Subject: [PATCH] Fix rescuing errors in RedisProxy#increment --- lib/rack/attack/store_proxy/redis_proxy.rb | 8 ++------ spec/integration/offline_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/rack/attack/store_proxy/redis_proxy.rb b/lib/rack/attack/store_proxy/redis_proxy.rb index 9fe2bc8..1bcb4b4 100644 --- a/lib/rack/attack/store_proxy/redis_proxy.rb +++ b/lib/rack/attack/store_proxy/redis_proxy.rb @@ -31,16 +31,12 @@ module Rack end def increment(key, amount, options = {}) - count = nil - rescuing do pipelined do - count = incrby(key, amount) + incrby(key, amount) expire(key, options[:expires_in]) if options[:expires_in] - end + end.first end - - count.value if count end def delete(key, _options = {}) diff --git a/spec/integration/offline_spec.rb b/spec/integration/offline_spec.rb index 26779a8..f9bacab 100644 --- a/spec/integration/offline_spec.rb +++ b/spec/integration/offline_spec.rb @@ -45,3 +45,15 @@ if defined?(::Dalli) end end end + +if defined?(Redis) + describe 'when Redis is offline' do + include OfflineExamples + + before do + @cache = Rack::Attack::Cache.new + # Use presumably unused port for Redis client + @cache.store = Redis.new(host: '127.0.0.1', port: 3333) + end + end +end