TokenBucketAlgorithm
TokenBucketAlgorithm
Token bucket algorithm for bursty traffic with steady refill.
Signature
class TokenBucketAlgorithm implements RateLimitAlgorithm {
public readonly type: RateLimitAlgorithmType = 'token-bucket';
constructor(storage: RateLimitStorage, config: TokenBucketConfig)
consume(key: string) => Promise<RateLimitResult>;
reset(key: string) => Promise<void>;
}
- Implements:
RateLimitAlgorithm
type
property
constructor
method
(storage: RateLimitStorage, config: TokenBucketConfig) => TokenBucketAlgorithmCreate a token-bucket algorithm bound to a storage backend.
consume
method
(key: string) => Promise<RateLimitResult>Record one attempt and return the current bucket status for this key.
reset
method
(key: string) => Promise<void>Reset the stored key state for this limiter.