ex_limiter v0.1.0 ExLimiter View Source

Configurable, leaky bucket rate limiting. You can define your own storage backend by implementing the ExLimiter.Storage behaviour, and configuring it with

config :ex_limiter, :storage, MyStorage

usage once configured is:

case ExLimiter.consume(bucket, 1, scale: 1000, limit: 5) do
  {:ok, bucket} -> #do some work
  {:error, :rate_limited} -> #fail
end

Additionally, if you want to have multiple rate limiters with diverse backend implementations, you can use the ExLimiter.Base macro, like so:

defmodule MyLimiter do
  use ExLimiter.Base, storage: MyStorage
end

Link to this section Summary

Functions

Consumes amount from the rate limiter aliased by bucket

Link to this section Functions

Link to this function consume(bucket, amount \\ 1, opts \\ []) View Source
consume(bucket :: binary(), amount :: integer(), opts :: keyword()) ::
  {:ok, ExLimiter.Bucket.t()} |
  {:error, :rate_limited}

Consumes amount from the rate limiter aliased by bucket.

opts params are:

  • :limit - the maximum amount for the rate limiter (default 10)
  • :scale - the duration under which :limit applies in milliseconds
Link to this function remaining(bucket, opts \\ []) View Source