View Source Hammer.Redis (hammer_backend_redis v7.0.0-rc.0)

This backend uses the Redix library to connect to Redis.

defmodule MyApp.RateLimit do
  # the default prefix is "MyApp.RateLimit:"
  # the default timeout is :infinity
  use Hammer, backend: Hammer.Redis, prefix: "MyApp.RateLimit:", timeout: :infinity
end

MyApp.RateLimit.start_link(url: "redis://localhost:6379")

# increment and timeout arguments are optional
# by default increment is 1 and timeout is as defined in the module
{:allow, _count} = MyApp.RateLimit.hit(key, scale, limit)
{:allow, _count} = MyApp.RateLimit.hit(key, scale, limit, _increment = 1, _timeout = :infinity)

Summary

Types

redis_opts()

@type redis_opts() :: {:url, String.t()} | Keyword.t()