Class: Rack::Attack::StoreProxy::RedisStoreProxy
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Rack::Attack::StoreProxy::RedisStoreProxy
- Defined in:
- lib/rack/attack/store_proxy.rb
Instance Method Summary collapse
- #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.
23 24 25 |
# File 'lib/rack/attack/store_proxy.rb', line 23 def initialize(store) super(store) end |
Instance Method Details
#increment(key, amount, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rack/attack/store_proxy.rb', line 43 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 nil end |
#read(key) ⇒ Object
27 28 29 30 31 |
# File 'lib/rack/attack/store_proxy.rb', line 27 def read(key) self.get(key) rescue Redis::BaseError nil end |
#write(key, value, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/rack/attack/store_proxy.rb', line 33 def write(key, value, ={}) if (expires_in = [:expires_in]) self.setex(key, expires_in, value) else self.set(key, value) end rescue Redis::BaseError nil end |