A Redis Cluster backend for the Hammer rate-limiter.
Hammer-backend-redis-cluster
can be installed by adding hammer_backend_redis_cluster
to your list of dependencies in mix.exs
, pointing to the proper GitHub repo:
def deps do
[{:hammer_backend_redis_cluster, git: "https://github.com/stiang/hammer-backend-redis-cluster.git"},
{:hammer, "~> 6.0"}]
end
Configure the :hammer
application to use the Redis backend:
config :hammer,
backend: {Hammer.Backend.RedisCluster, [expiry_ms: 60_000 * 60 * 2,
redix_remastered_config: [host: "localhost",
port: 6379]]}
(the redix_remastered_config
arg is a keyword-list which is passed to
RedixCluster, it's also aliased to redis_remastered_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.
See the Hammer Tutorial for more.
On hexdocs (original package): https://hexdocs.pm/hammer_backend_redis/