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

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

Instance Method Summary collapse

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, 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
    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, options={})
  if (expires_in = options[:expires_in])
    self.setex(key, expires_in, value)
  else
    self.set(key, value)
  end
  rescue Redis::BaseError
    nil
end