class RateLimiter
- RateLimiter
- Reference
- Object
Defined in:
rate_limiter.crConstant Summary
-
DEFAULT_BUCKET_SIZE =
60 -
Default limits
-
DEFAULT_CLEANUP_INTERVAL =
300 -
DEFAULT_REFILL_RATE =
10
Constructors
Instance Method Summary
-
#allow?(key : String, cost : Int32 = 1) : Bool
Check if request is allowed and consume a token Returns true if allowed, false if rate limited
-
#remaining(key : String) : Int32
Get remaining tokens for a key
-
#reset(key : String)
Reset bucket for a key
-
#retry_after(key : String) : Float64
Get seconds until a token is available
Constructor Detail
def self.new(bucket_size : Int32 = DEFAULT_BUCKET_SIZE, refill_rate : Float64 = DEFAULT_REFILL_RATE.to_f)
#
Instance Method Detail
def allow?(key : String, cost : Int32 = 1) : Bool
#
Check if request is allowed and consume a token Returns true if allowed, false if rate limited