limitex v0.1.1 Limitex.RateLimiter View Source
A distributed rate limiter for expensive requests based on Token Bucket algorithm.
Link to this section Summary
Functions
Check if the action you wish to perform is within the bounds of the rate-limit.
Returns a specification to start this module under a supervisor.
Link to this section Types
Link to this type
bucket_info()
View Sourcebucket_info() :: {key :: bucket_key(), count :: integer(), created :: integer(), updated :: integer()}
Link to this section Functions
Check if the action you wish to perform is within the bounds of the rate-limit.
id
: String name of the bucket. Usually comprised of a fixed prefix and some dynamic string appendedscale_ms
: Integer indicating size of bucket in millisecondslimit
: Integer maximum count of actions within the bucket
Example:
user_id = 42076
case check_rate("file_upload:#{user_id}", 60_000, 5) do
{:ok, _count} ->
# do the file upload
{:error, :rate_limited} ->
# render an error page or something
end
Returns a specification to start this module under a supervisor.
See Supervisor
.