Skip to content

Commit 9cf227a

Browse files
authored
Merge pull request #445 from fatkodima/redis-proxy-increment
Fix rescuing errors in RedisProxy#increment
2 parents 6cfd036 + 2fac641 commit 9cf227a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/rack/attack/store_proxy/redis_proxy.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ def write(key, value, options = {})
3131
end
3232

3333
def increment(key, amount, options = {})
34-
count = nil
35-
3634
rescuing do
3735
pipelined do
38-
count = incrby(key, amount)
36+
incrby(key, amount)
3937
expire(key, options[:expires_in]) if options[:expires_in]
40-
end
38+
end.first
4139
end
42-
43-
count.value if count
4440
end
4541

4642
def delete(key, _options = {})

spec/integration/offline_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,15 @@
4545
end
4646
end
4747
end
48+
49+
if defined?(Redis)
50+
describe 'when Redis is offline' do
51+
include OfflineExamples
52+
53+
before do
54+
@cache = Rack::Attack::Cache.new
55+
# Use presumably unused port for Redis client
56+
@cache.store = Redis.new(host: '127.0.0.1', port: 3333)
57+
end
58+
end
59+
end

0 commit comments

Comments
 (0)