diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index 8334dc6d..3f4cdef9 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -18,6 +18,7 @@ class MissingStoreError < StandardError; end autoload :DalliProxy, 'rack/attack/store_proxy/dalli_proxy' autoload :MemCacheProxy, 'rack/attack/store_proxy/mem_cache_proxy' autoload :RedisStoreProxy, 'rack/attack/store_proxy/redis_store_proxy' + autoload :RedisProxy, 'rack/attack/store_proxy/redis_proxy' autoload :Fail2Ban, 'rack/attack/fail2ban' autoload :Allow2Ban, 'rack/attack/allow2ban' diff --git a/lib/rack/attack/store_proxy.rb b/lib/rack/attack/store_proxy.rb index d83cab98..89f3e031 100644 --- a/lib/rack/attack/store_proxy.rb +++ b/lib/rack/attack/store_proxy.rb @@ -1,7 +1,7 @@ module Rack class Attack module StoreProxy - PROXIES = [DalliProxy, MemCacheProxy, RedisStoreProxy].freeze + PROXIES = [DalliProxy, MemCacheProxy, RedisStoreProxy, RedisProxy].freeze ACTIVE_SUPPORT_WRAPPER_CLASSES = Set.new(['ActiveSupport::Cache::MemCacheStore', 'ActiveSupport::Cache::RedisStore']).freeze ACTIVE_SUPPORT_CLIENTS = Set.new(['Redis::Store', 'Dalli::Client', 'MemCache']).freeze diff --git a/lib/rack/attack/store_proxy/redis_proxy.rb b/lib/rack/attack/store_proxy/redis_proxy.rb new file mode 100644 index 00000000..ab5e916f --- /dev/null +++ b/lib/rack/attack/store_proxy/redis_proxy.rb @@ -0,0 +1,29 @@ +require 'delegate' + +module Rack + class Attack + module StoreProxy + class RedisProxy < RedisStoreProxy + def self.handle?(store) + defined?(::Redis) && store.is_a?(::Redis) + end + + def initialize(store) + super(store) + end + + def get(key, _options = {}) + super(key) + end + + def setex(key, ttl, value, _options = {}) + super(key, ttl, value) + end + + def setnx(key, value, _options = {}) + super(key, value) + end + end + end + end +end