Rate Limiter
An interface for acquiring and releasing rate limit tokens
Terms:
key- a unique identifier for the entity or operation being rate limitedbucket- a container for rate limit tokens applied to a specific keytoken- a unit of rate limit capacity. When we go to perform a rate limited operation, we attempt to consume a token from the bucket. If successful, we can perform the operation.
See also: https://en.wikipedia.org/wiki/Token_bucket
Types
Functions
Returns how many tokens remain in the bucket. Note that this data may be stale when it comes back, as time has elapsed and other pods could have taken tokens in the meantime.
Consumes amount tokens from the bucket associated with the given key This will raise any exception thrown by the bucket4j proxy manager implementation, e.g. subclasses of JedisException when using the Jedis implementation.
Releases amount tokens back to the bucket associated with the given key This will raise any exception thrown by the bucket4j proxy manager implementation, e.g. subclasses of JedisException when using the Jedis implementation.
Resets the bucket back to its maximum capacity
This tests whether amount tokens are available in the bucket associated with the given key. It is essentially a dry run of consumeToken. Note that this data may be stale when it comes back, as time has elapsed and other pods could have taken tokens in the meantime.
Executes the given function if a token is available This will raise any exception thrown by the bucket4j proxy manager implementation, e.g. subclasses of JedisException when using the Jedis implementation.