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
- #increment(key, amount, options = {}) ⇒ Object
-
#initialize(store) ⇒ RedisStoreProxy
constructor
A new instance of RedisStoreProxy.
- #raw_read(key) ⇒ Object
- #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
#increment(key, amount, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 36 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 |
#raw_read(key) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 15 def raw_read(key) #https://github.com/redis-store/redis-store/issues/96 # if raw not specified results in 'marshal data too short' error self.get(key, raw: true) rescue Redis::BaseError end |
#read(key) ⇒ Object
22 23 24 25 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 22 def read(key) self.get(key) rescue Redis::BaseError end |
#write(key, value, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rack/attack/store_proxy/redis_store_proxy.rb', line 27 def write(key, value, ={}) if (expires_in = [:expires_in]) self.setex(key, expires_in, value) else self.set(key, value) end rescue Redis::BaseError end |