View Source Overview
A Clustered Redis backend for the Hammer rate-limiter
Hammer is a rate-limiter for the Elixir language. It's killer feature is a pluggable backend system, allowing you to use whichever storage suits your needs.
This package provides a Clustered Redis backend for Hammer, using the eredis_cluster library to connect to the Redis server.
To get started, read
the Hammer Tutorial first, then add
the hammer_backend_eredis_cluster
dependency:
def deps do
[{:hammer_backend_eredis_cluster, "~> 1.0"},
{:hammer, "~> 6.1"}]
end
... then configure the :hammer
application to use the Redis backend:
config :hammer,
backend: {Hammer.Backend.Eredis, [expiry_ms: 60_000 * 60 * 2,
eredis_cluster_init_servers: [{"localhost", 6379}, {"localhost", 6380}, {"localhost", 6381}]]}
(the redix_config
arg is a keyword-list which is passed to Redix, it's also
aliased to redis_config
, with an s
)
And that's it, calls to Hammer.check_rate/3
and so on will use Redis to store
the rate-limit counters.