mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Merge pull request #49 from wkimeria/wip/dont_raise_redis_error
If redis client throws exception, don't raise it
This commit is contained in:
commit
1abe292240
2 changed files with 34 additions and 0 deletions
|
|
@ -26,6 +26,8 @@ module Rack
|
||||||
|
|
||||||
def read(key)
|
def read(key)
|
||||||
self.get(key)
|
self.get(key)
|
||||||
|
rescue Redis::BaseError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def write(key, value, options={})
|
def write(key, value, options={})
|
||||||
|
|
@ -34,6 +36,8 @@ module Rack
|
||||||
else
|
else
|
||||||
self.set(key, value)
|
self.set(key, value)
|
||||||
end
|
end
|
||||||
|
rescue Redis::BaseError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment(key, amount, options={})
|
def increment(key, amount, options={})
|
||||||
|
|
@ -43,6 +47,8 @@ module Rack
|
||||||
self.expire(key, options[:expires_in]) if options[:expires_in]
|
self.expire(key, options[:expires_in]) if options[:expires_in]
|
||||||
end
|
end
|
||||||
count.value if count
|
count.value if count
|
||||||
|
rescue Redis::BaseError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,34 @@ if ENV['TEST_INTEGRATION']
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "should not error if redis is not running" do
|
||||||
|
before {
|
||||||
|
@cache = Rack::Attack::Cache.new
|
||||||
|
@key = "rack::attack:cache-test-key"
|
||||||
|
@expires_in = 1
|
||||||
|
# Use ip reserved for documentation to ensure it does not exist
|
||||||
|
# http://tools.ietf.org/html/rfc5737
|
||||||
|
@cache.store = ActiveSupport::Cache::RedisStore.new(:host => '203.0.113.0', :port => 3333)
|
||||||
|
}
|
||||||
|
describe "write" do
|
||||||
|
it "should not raise exception" do
|
||||||
|
@cache.write("cache-test-key", "foobar", 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "read" do
|
||||||
|
it "should not raise exception" do
|
||||||
|
@cache.read("cache-test-key")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "do_count" do
|
||||||
|
it "should not raise exception" do
|
||||||
|
@cache.send(:do_count, @key, @expires_in)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts 'Skipping cache store integration tests (set ENV["TEST_INTEGRATION"] to enable)'
|
puts 'Skipping cache store integration tests (set ENV["TEST_INTEGRATION"] to enable)'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue