Class: Rack::Attack::StoreProxy::RedisProxy
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Rack::Attack::StoreProxy::RedisProxy
- Defined in:
- lib/rack/attack/store_proxy/redis_proxy.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #delete(key, _options = {}) ⇒ Object
- #increment(key, amount, options = {}) ⇒ Object
-
#initialize(*args) ⇒ RedisProxy
constructor
A new instance of RedisProxy.
- #read(key) ⇒ Object
- #write(key, value, options = {}) ⇒ Object
Constructor Details
#initialize(*args) ⇒ RedisProxy
Returns a new instance of RedisProxy.
9 10 11 12 13 14 15 |
# File 'lib/rack/attack/store_proxy/redis_proxy.rb', line 9 def initialize(*args) if Gem::Version.new(Redis::VERSION) < Gem::Version.new("3") warn 'RackAttack requires Redis gem >= 3.0.0.' end super(*args) end |
Class Method Details
.handle?(store) ⇒ Boolean
17 18 19 |
# File 'lib/rack/attack/store_proxy/redis_proxy.rb', line 17 def self.handle?(store) defined?(::Redis) && store.is_a?(::Redis) end |
Instance Method Details
#delete(key, _options = {}) ⇒ Object
47 48 49 50 |
# File 'lib/rack/attack/store_proxy/redis_proxy.rb', line 47 def delete(key, = {}) del(key) rescue Redis::BaseError end |
#increment(key, amount, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rack/attack/store_proxy/redis_proxy.rb', line 35 def increment(key, amount, = {}) count = nil pipelined do count = incrby(key, amount) expire(key, [:expires_in]) if [:expires_in] end count.value if count rescue Redis::BaseError end |
#read(key) ⇒ Object
21 22 23 24 |
# File 'lib/rack/attack/store_proxy/redis_proxy.rb', line 21 def read(key) get(key) rescue Redis::BaseError end |
#write(key, value, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/rack/attack/store_proxy/redis_proxy.rb', line 26 def write(key, value, = {}) if (expires_in = [:expires_in]) setex(key, expires_in, value) else set(key, value) end rescue Redis::BaseError end |