Class: Limit::TokenBucketRateLimiter
- Inherits:
-
BaseRateLimiter
- Object
- BaseRateLimiter
- Limit::TokenBucketRateLimiter
- Defined in:
- lib/limit.rb
Overview
TokenBucketRateLimiter implements the token bucket algorithm that’ll allow the steady refill rate
Constant Summary collapse
- REQUIRED_KEYS =
limit_calculator: Lambda that takes a key(String) and returns hash: Integer, refill_rate: Integer, refill_interval: Integer
i[bucket_capacity refill_rate refill_interval].freeze
Instance Attribute Summary
Attributes inherited from BaseRateLimiter
#identifier_prefix, #limit_calculator
Instance Method Summary collapse
Methods inherited from BaseRateLimiter
connection, #get_key, #initialize, load_script, logger
Constructor Details
This class inherits a constructor from Limit::BaseRateLimiter
Instance Method Details
#allowed?(key) ⇒ Boolean
186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/limit.rb', line 186 def allowed?(key) limit_data = get_current_limit(key) result = eval_sha( [get_key(key)], [ limit_data[:bucket_capacity], limit_data[:refill_rate], limit_data[:refill_interval] ] ) result == 1 end |