# `Hammer.Redis`
[🔗](https://github.com/ExHammer/hammer-backend-redis/blob/v7.1.1/lib/hammer/redis.ex#L1)

This backend uses the [Redix](https://hex.pm/packages/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)

The Redis backend supports the following algorithms:
  - `:fix_window` - Fixed window rate limiting (default)
    Simple counting within fixed time windows. See [Hammer.Redis.FixWindow](Hammer.Redis.FixWindow.html) for more details.

  - `:sliding_window` - Sliding window rate limiting
    Simple counting within sliding time windows. See [Hammer.Redis.SlidingWindow](Hammer.Redis.SlidingWindow.html) for more details.

  - `:leaky_bucket` - Leaky bucket rate limiting
    Smooth rate limiting with a fixed rate of tokens. See [Hammer.Redis.LeakyBucket](Hammer.Redis.LeakyBucket.html) for more details.

  - `:token_bucket` - Token bucket rate limiting
    Flexible rate limiting with bursting capability. See [Hammer.Redis.TokenBucket](Hammer.Redis.TokenBucket.html) for more details.

# `redis_option`

```elixir
@type redis_option() :: {:url, String.t()} | {:name, String.t()}
```

# `redis_options`

```elixir
@type redis_options() :: [redis_option()]
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
