Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a Redis proxy compatible with ~>redis-3.0. #348

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rack/attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion lib/rack/attack/store_proxy.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 29 additions & 0 deletions lib/rack/attack/store_proxy/redis_proxy.rb
Original file line number Diff line number Diff line change
@@ -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