Class: Rack::Attack::StoreProxy::RedisStoreProxy
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Rack::Attack::StoreProxy::RedisStoreProxy
- Defined in:
- lib/rack/attack/store_proxy/redis_store_proxy.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete(key, options = {}) ⇒ Object
- #increment(key, amount, options = {}) ⇒ Object
-
#initialize(store) ⇒ RedisStoreProxy
constructor
A new instance of RedisStoreProxy.
- #read(key) ⇒ Object
- #write(key, value, options = {}) ⇒ Object
Constructor Details
#initialize(store) ⇒ RedisStoreProxy
Returns a new instance of RedisStoreProxy.
11 12 13 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 11 def initialize(store) super(store) end |
Class Method Details
.handle?(store) ⇒ Boolean
7 8 9 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 7 def self.handle?(store) defined?(::Redis::Store) && store.is_a?(::Redis::Store) end |
Instance Method Details
#delete(key, options = {}) ⇒ Object
39 40 41 42 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 39 def delete(key, ={}) self.del(key) rescue Redis::BaseError end |
#increment(key, amount, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 29 def increment(key, amount, ={}) count = nil self.pipelined do count = self.incrby(key, amount) self.expire(key, [:expires_in]) if [:expires_in] end count.value if count rescue Redis::BaseError end |
#read(key) ⇒ Object
15 16 17 18 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 15 def read(key) self.get(key, raw: true) rescue Redis::BaseError end |
#write(key, value, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 20 def write(key, value, ={}) if (expires_in = [:expires_in]) self.setex(key, expires_in, value, raw: true) else self.set(key, value, raw: true) end rescue Redis::BaseError end |