Class: Rack::Attack::StoreProxy::RedisStoreProxy

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rack/attack/store_proxy/redis_store_proxy.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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, options={})
  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, options={})
  count = nil
  self.pipelined do
    count = self.incrby(key, amount)
    self.expire(key, options[:expires_in]) if options[: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, options={})
  if (expires_in = options[:expires_in])
    self.setex(key, expires_in, value, raw: true)
  else
    self.set(key, value, raw: true)
  end
rescue Redis::BaseError
end