{
  "schema_version": 2,
  "id": "integrate/kong",
  "title": "Redis with Kong Gateway",
  "url": "https://redis.io/docs/latest/integrate/kong/",
  "summary": "Share rate limits across Kong Gateway nodes with Redis.",
  "tags": [
    "docs",
    "integrate",
    "oss",
    "rs",
    "rc"
  ],
  "last_updated": "2026-11-17T16:52:03Z",
  "children": [],
  "page_type": "content",
  "content_hash": "6656fa77583f11e6f70947000aac95f4d4d15b02eedf1bee1f2d4c7b9560de45",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[Kong Gateway](https://konghq.com/) is an API gateway. Its `rate-limiting` plugin can keep its\ncounters in Redis, so that several Kong nodes enforce one shared limit. See the [rate limiter use case](https://redis.io/docs/latest/develop/use-cases/rate-limiter) for when to choose\nthis pattern."
    },
    {
      "id": "requirements",
      "title": "Requirements",
      "role": "content",
      "text": "The examples on this page were run with the open source Kong Gateway 3.9 image (`kong:3.9`) in\nDB-less mode against Redis 8.0, with two Kong nodes sharing one Redis server.\n\nYou also need a running Redis server. You can run one locally with\n[Redis Open Source](https://redis.io/docs/latest/operate/oss_and_stack/install/archive/install-redis),\nuse [Docker](https://hub.docker.com/_/redis), or connect to\n[Redis Cloud](https://redis.io/cloud/)."
    },
    {
      "id": "limit-requests-with-a-redis-policy",
      "title": "Limit requests with a Redis policy",
      "role": "limits",
      "text": "The `rate-limiting` plugin's `policy` setting selects where Kong keeps the counters:\n\n| Policy | Where the counters live |\n|--------|-------------------------|\n| `local` (default) | In the memory of each Kong node, so each node enforces its own limit. |\n| `cluster` | In Kong's database. |\n| `redis` | In Redis, shared by every node that uses the same Redis server. |\n\nThis declarative configuration allows 3 requests a minute on a route and keeps the counters in\nRedis:\n\n[code example]\n\nIn a test with two Kong nodes behind the same Redis server, five requests that alternated\nbetween the nodes returned `200`, `200`, `200`, `429`, and `429`. Each response carried\n`X-RateLimit-Remaining-Minute` and `RateLimit-Remaining` headers, and the `429` responses\nadded `Retry-After: 60`."
    },
    {
      "id": "redis-connection-options",
      "title": "Redis connection options",
      "role": "content",
      "text": "The `redis` settings of the plugin, from the\n[Kong plugin reference](https://developer.konghq.com/plugins/rate-limiting/reference/):\n\n| Setting | Default | Notes |\n|---------|---------|-------|\n| `host`, `port` | none, `6379` | The Redis server. |\n| `username`, `password` | none | For [ACL](https://redis.io/docs/latest/operate/oss_and_stack/management/security/acl) authentication (Redis 6.0 or later). If you don't set a password, Kong sends no `AUTH` command. |\n| `database` | `0` | The [logical database](https://redis.io/docs/latest/commands/select). |\n| `ssl`, `ssl_verify`, `server_name` | `false`, `true` | Transport Layer Security (TLS) settings. |\n| `timeout` | `2000` | The connection timeout in milliseconds. |"
    },
    {
      "id": "what-kong-stores-in-redis",
      "title": "What Kong stores in Redis",
      "role": "content",
      "text": "Kong keeps one counter for each client and time window, as a string:\n\n[code example]\n\nThe counter has a time to live (TTL) of 60 seconds for a `minute` limit. After the five\nrequests above it held `5`: Kong counts the requests that it rejects as well as the ones that it\nallows."
    },
    {
      "id": "when-redis-is-unavailable",
      "title": "When Redis is unavailable",
      "role": "content",
      "text": "In the test, with the Redis server stopped, Kong let every request through (`200`), and each\none took about 2 seconds, which is the default `timeout`. The gateway fails open, but its\nlatency rises by the connection timeout, so lower `timeout` if that matters to you."
    },
    {
      "id": "kong-gateway-enterprise",
      "title": "Kong Gateway Enterprise",
      "role": "content",
      "text": "According to the Kong documentation, some Redis features are available only in Kong Gateway\nEnterprise:\n\n- **Rate Limiting Advanced** adds Redis Sentinel and Redis Cluster support.\n- **Proxy Cache Advanced** caches responses in Redis. The open source `proxy-cache` plugin stores\n  its cache in memory only.\n- The `session` plugin stores sessions in the cookie or in Kong's database. It has no Redis\n  storage option.\n\nThe examples on this page don't cover these Enterprise plugins."
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "- [Rate Limiting plugin](https://developer.konghq.com/plugins/rate-limiting/)\n- [Kong Gateway documentation](https://developer.konghq.com/gateway/)"
    }
  ],
  "examples": [
    {
      "id": "limit-requests-with-a-redis-policy-ex0",
      "language": "yaml",
      "code": "_format_version: \"3.0\"\nservices:\n  - name: demo\n    url: http://<your-upstream>\n    routes:\n      - name: demo-route\n        paths:\n          - /api\n        plugins:\n          - name: rate-limiting\n            config:\n              minute: 3\n              policy: redis\n              redis:\n                host: <your-redis-host>\n                port: 6379\n                database: 0",
      "section_id": "limit-requests-with-a-redis-policy"
    },
    {
      "id": "what-kong-stores-in-redis-ex0",
      "language": "plaintext",
      "code": "ratelimit:<route-id>:<service-id>:<client-ip>:<window-start-ms>:minute",
      "section_id": "what-kong-stores-in-redis"
    }
  ]
}
