{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.krakend.io/schema/v2.9/qos/ratelimit/redis.json",
  "description": "Enterprise only. Redis-backed service ratelimit",
  "type": "object",
  "anyOf": [
    {
      "required": [ "connection_pool", "max_rate" ]
    },
    {
      "required": [ "connection_pool", "client_max_rate" ]
    },
    {
      "required": [ "connection_name", "max_rate" ]
    },
    {
      "required": [ "connection_name", "client_max_rate" ]
    }
  ],
  "properties": {
    "capacity": {
      "title": "Capacity",
      "description": "Defines the maximum number of [tokens a bucket can hold](https://www.krakend.io/docs/throttling/token-bucket/), or said otherwise, how many requests will you accept from **all users together** at **any given instant**. When the gateway starts, the bucket is full. As requests from users come, the remaining tokens in the bucket decrease. At the same time, the `max_rate` refills the bucket at the desired rate until its maximum capacity is reached. The default value for the `capacity` is the `max_rate` value expressed in seconds or 1 for smaller fractions. When unsure, use the same number as `max_rate`.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
      "default": 1,
      "type": "integer"
    },
    "client_capacity": {
      "title": "Client capacity",
      "description": "Defines the maximum number of [tokens a bucket can hold](https://www.krakend.io/docs/throttling/token-bucket/), or said otherwise, how many requests will you accept from **each individual user** at **any given instant**. Works just as `capacity`, but instead of having one bucket for all users, keeps a counter for every connected client and endpoint, and refills from `client_max_rate` instead of `max_rate`. The client is recognized using the `strategy` field (an IP address, a token, a header, etc.). The default value for the `client_capacity` is the `client_max_rate` value expressed in seconds or 1 for smaller fractions. When unsure, use the same number as `client_max_rate`.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
      "default": 1,
      "type": "integer"
    },
    "client_max_rate": {
      "title": "Client max rate",
      "description": "Number of tokens you add to the [Token Bucket](https://www.krakend.io/docs/throttling/token-bucket/) for each individual user (*user quota*) in the time interval you want (`every`). The remaining tokens in the bucket are the requests a specific user can do. It keeps a counter for every client and endpoint. Keep in mind that every KrakenD instance keeps its counters in memory for **every single client**.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
      "type": "number"
    },
    "connection_name": {
      "title": "Connection Name",
      "description": "The connection pool name or cluster name that is used by this ratelimit. The value must match what you configured in the [Redis Connection Pool](https://www.krakend.io/docs/enterprise/service-settings/redis-connection-pools/)",
      "type": "string"
    },
    "connection_pool": {
      "title": "Connection Pool Name",
      "description": "The connection pool name that is used by this ratelimit. The value must match what you configured in the [Redis Connection Pool](https://www.krakend.io/docs/enterprise/service-settings/redis-connection-pools/)",
      "deprecated": true,
      "type": "string"
    },
    "every": {
      "title": "Time window",
      "description": "Time period in which the maximum rates operate. For instance, if you set an `every` of `10m` and a rate of `5`, you are allowing 5 requests every ten minutes.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
      "default": "1s",
      "$ref": "../../timeunits.json#/$defs/timeunit",
      "type": "string"
    },
    "key": {
      "title": "Header or Param key",
      "description": "Available when using `client_max_rate` and you have set a `strategy` equal to `header` or `param`. It makes no sense in other contexts. For `header` it is the header name containing the user identification (e.g., `Authorization` on tokens, or `X-Original-Forwarded-For` for IPs). When they contain a list of space-separated IPs, it will take the IP from the client that hit the first trusted proxy. For `param` it is the name of the placeholder used in the endpoint, like `id_user` for an endpoint `/user/{id_user}`.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
      "examples": [ "X-Tenant", "Authorization", "id_user" ],
      "type": "string"
    },
    "max_rate": {
      "title": "Max rate",
      "description": "Sets the maximum number of requests all users can do in the given time frame. Internally uses the [Token Bucket](https://www.krakend.io/docs/throttling/token-bucket/) algorithm. The absence of `max_rate` in the configuration or a `0` is the equivalent to no limitation. You can use decimals if needed.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
      "type": "number"
    },
    "on_failure_allow": {
      "title": "On Failure Allow?",
      "description": "Whether you want to allow a request to continue when the Redis connection is failing or not. The default behavior blocks the request if Redis is not responding correctly",
      "default": false,
      "type": "boolean"
    },
    "strategy": {
      "title": "Strategy",
      "description": "Available when using `client_max_rate`. Sets the strategy you will use to set client counters. Choose `ip` when the restrictions apply to the client's IP address, or set it to `header` when there is a header that identifies a user uniquely. That header must be defined with the `key` entry.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
      "enum": [ "ip", "header", "param" ]
    }
  }
}
