Class: Rack::Ratelimit::RedisCounter
- Inherits:
-
Object
- Object
- Rack::Ratelimit::RedisCounter
- Defined in:
- lib/rack/ratelimit.rb
Instance Method Summary collapse
-
#increment(classification, timestamp) ⇒ Object
Increment the request counter and return the current count.
-
#initialize(redis, name, period) ⇒ RedisCounter
constructor
A new instance of RedisCounter.
Constructor Details
#initialize(redis, name, period) ⇒ RedisCounter
Returns a new instance of RedisCounter.
182 183 184 |
# File 'lib/rack/ratelimit.rb', line 182 def initialize(redis, name, period) @redis, @name, @period = redis, name, period end |
Instance Method Details
#increment(classification, timestamp) ⇒ Object
Increment the request counter and return the current count.
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/rack/ratelimit.rb', line 187 def increment(classification, ) key = 'rack-ratelimit/%s/%s/%i' % [@name, classification, ] # Returns [count, expire_ok] response for each multi command. # Return the first, the count. @redis.multi do |redis| redis.incr key redis.expire key, @period end.first end |