mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Merge pull request #445 from fatkodima/redis-proxy-increment
Fix rescuing errors in RedisProxy#increment
This commit is contained in:
commit
9cf227a32e
2 changed files with 14 additions and 6 deletions
|
|
@ -31,18 +31,14 @@ module Rack
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment(key, amount, options = {})
|
def increment(key, amount, options = {})
|
||||||
count = nil
|
|
||||||
|
|
||||||
rescuing do
|
rescuing do
|
||||||
pipelined do
|
pipelined do
|
||||||
count = incrby(key, amount)
|
incrby(key, amount)
|
||||||
expire(key, options[:expires_in]) if options[:expires_in]
|
expire(key, options[:expires_in]) if options[:expires_in]
|
||||||
|
end.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
count.value if count
|
|
||||||
end
|
|
||||||
|
|
||||||
def delete(key, _options = {})
|
def delete(key, _options = {})
|
||||||
rescuing { del(key) }
|
rescuing { del(key) }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -45,3 +45,15 @@ if defined?(::Dalli)
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue