{
  "schema_version": 2,
  "id": "develop/use-cases/session-store",
  "title": "Redis session store",
  "url": "https://redis.io/docs/latest/develop/use-cases/session-store/",
  "summary": "Store web sessions in Redis.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc"
  ],
  "last_updated": "2026-09-16T17:06:11+01:00",
  "children": [
    {
      "id": "develop/use-cases/session-store/redis-py",
      "summary": "Implement a Redis-backed session store in Python with redis-py",
      "title": "Redis session store with redis-py",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/redis-py/"
    },
    {
      "id": "develop/use-cases/session-store/nodejs",
      "summary": "Implement a Redis-backed session store in Node.js with node-redis",
      "title": "Redis session store with node-redis",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/nodejs/"
    },
    {
      "id": "develop/use-cases/session-store/go",
      "summary": "Implement a Redis-backed session store in Go with go-redis",
      "title": "Redis session store with Go",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/go/"
    },
    {
      "id": "develop/use-cases/session-store/java-jedis",
      "summary": "Implement a Redis-backed session store in Java with Jedis",
      "title": "Redis session store with Java and Jedis",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/java-jedis/"
    },
    {
      "id": "develop/use-cases/session-store/java-lettuce",
      "summary": "Implement a Redis-backed session store in Java with Lettuce",
      "title": "Redis session store with Java (Lettuce)",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/java-lettuce/"
    },
    {
      "id": "develop/use-cases/session-store/dotnet",
      "summary": "Implement a Redis-backed session store in C#/.NET with StackExchange.Redis",
      "title": "Redis session store with C#/.NET",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/dotnet/"
    },
    {
      "id": "develop/use-cases/session-store/php",
      "summary": "Implement a Redis-backed session store in PHP with Predis",
      "title": "Redis session store with PHP",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/php/"
    },
    {
      "id": "develop/use-cases/session-store/ruby",
      "summary": "Implement a Redis-backed session store in Ruby with redis-rb",
      "title": "Redis session store with Ruby",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/ruby/"
    },
    {
      "id": "develop/use-cases/session-store/rust",
      "summary": "Implement a Redis-backed session store in Rust with redis-rs",
      "title": "Redis session store with Rust",
      "url": "https://redis.io/docs/latest/develop/use-cases/session-store/rust/"
    }
  ],
  "page_type": "content",
  "content_hash": "38a86244cfd4726d1cb489f0e6f05a3d44c2684f64c260baaa07e2bf0bf69bbd",
  "sections": [
    {
      "id": "when-to-use-a-session-store",
      "title": "When to use a session store",
      "role": "overview",
      "text": "Use a Redis session store when you need to share per-user session state (login context, shopping carts, preferences) across stateless application servers without sticky sessions or database round-trips."
    },
    {
      "id": "why-the-problem-is-hard",
      "title": "Why the problem is hard",
      "role": "content",
      "text": "HTTP is stateless, so you must rely on external state to recognize a returning user between requests.\nSome of the obvious approaches have significant drawbacks:\n\n-   **Storing sessions on individual app servers**: this requires\n    [sticky routing](https://en.wikipedia.org/wiki/Load_balancing_(computing)#Persistence), which creates\n    hot spots and precludes [failover](https://en.wikipedia.org/wiki/Failover).\n-   **Moving session reads to a relational database**: this adds 5–20 ms per request. If you have\n    thousands of concurrent users then session reads dominate connection pools. This turns every page load\n    into a contention point that degrades the primary database for all other workloads.\n\nSessions need automatic cleanup without external sweep jobs. You will incur\ndirect business costs (abandoned carts, forced re-authentication, interrupted checkouts) if\nyou lose sessions, so durability matters more than it does with pure caching.\n\nAt operational scale, you also need to run queries against multiple sessions (for example, find all\ncarts containing a recalled product, count sessions per tenant), which is more complicated than just reading individual sessions."
    },
    {
      "id": "what-you-can-expect-from-a-redis-solution",
      "title": "What you can expect from a Redis solution",
      "role": "content",
      "text": "You can:\n\n-   Eliminate sticky sessions so any instance can serve any user behind a load balancer.\n-   Expire inactive sessions automatically without cleanup jobs or database sweeps.\n-   Update individual session fields without re-serializing the full session.\n-   Track sessions across multiple devices per user, including logout-all.\n-   Query across active sessions for operational and security tasks without key scanning.\n-   Retain session data across deployments and node restarts with configurable durability."
    },
    {
      "id": "how-redis-supports-the-solution",
      "title": "How Redis supports the solution",
      "role": "content",
      "text": "In practice, each session is stored as a Redis hash — one hash per session ID — and the key is set to expire automatically so inactive sessions are cleaned up without any external job.\n\nRedis provides the following features that make it a good fit for session storage:\n\n-   [Hashes](https://redis.io/docs/latest/develop/data-types/hashes) for field-level session access without \n    deserializing an entire session blob.\n-   [`EXPIRE`](https://redis.io/docs/latest/commands/expire) with sliding TTL resets on each request so active \n    sessions stay alive while inactive ones are cleaned up automatically.\n-   [Sets](https://redis.io/docs/latest/develop/data-types/sets) ([`SADD`](https://redis.io/docs/latest/commands/sadd), \n    [`SMEMBERS`](https://redis.io/docs/latest/commands/smembers)) to track all sessions per user for multi-device \n    management ([`DEL`](https://redis.io/docs/latest/commands/del) plus [`SREM`](https://redis.io/docs/latest/commands/srem) \n    handle explicit logout or logout-all).\n-   AOF and RDB [persistence](https://redis.io/docs/latest/operate/oss_and_stack/management/persistence) to let \n    sessions survive process and node restarts within their expiration window. \n-   Secondary indexing (querying by field values rather than by key) via\n    [Redis Search](https://redis.io/docs/latest/develop/ai/search-and-query) to support\n    cross-session queries at runtime (finding affected carts, counting sessions by tenant)\n    without key scanning.\n-   Sub-millisecond latency on the request path, which is already on the same Redis instance\n    in most stacks."
    },
    {
      "id": "ecosystem",
      "title": "Ecosystem",
      "role": "content",
      "text": "The following libraries and frameworks provide Redis session store integrations:\n\n-   **Java**:\n    [Spring Session Data Redis](https://docs.spring.io/spring-session/reference/configuration/redis.html)\n-   **Node.js**: [`connect-redis`](https://www.npmjs.com/package/connect-redis)\n    ([express-session](https://www.npmjs.com/package/express-session) store)\n-   **Python**: [Flask-Session](https://flask-session.readthedocs.io/en/latest/),\n    [django-redis](https://pypi.org/project/django-redis/)\n-   **API gateways**: [Kong](https://docs.konghq.com/hub/kong-inc/session/),\n    [Envoy](https://www.envoyproxy.io/docs/envoy/latest/start/quick-start/configuration-dynamic-control-plane)\n    (Redis-backed session and token storage)"
    },
    {
      "id": "code-examples-to-build-your-own-redis-session-store",
      "title": "Code examples to build your own Redis session store",
      "role": "example",
      "text": "The following guides show how to build a simple Redis-backed session store.\nEach guide includes a runnable example to illustrate using the session store with a basic local\nweb server for each of the following client libraries:\n\n* [redis-py (Python)](https://redis.io/docs/latest/develop/use-cases/session-store/redis-py)\n* [node-redis (Node.js)](https://redis.io/docs/latest/develop/use-cases/session-store/nodejs)\n* [go-redis (Go)](https://redis.io/docs/latest/develop/use-cases/session-store/go)\n* [Jedis (Java)](https://redis.io/docs/latest/develop/use-cases/session-store/java-jedis)\n* [Lettuce (Java)](https://redis.io/docs/latest/develop/use-cases/session-store/java-lettuce)\n* [StackExchange.Redis (C#)](https://redis.io/docs/latest/develop/use-cases/session-store/dotnet)\n* [Predis (PHP)](https://redis.io/docs/latest/develop/use-cases/session-store/php)\n* [redis-rb (Ruby)](https://redis.io/docs/latest/develop/use-cases/session-store/ruby)\n* [redis-rs (Rust)](https://redis.io/docs/latest/develop/use-cases/session-store/rust)"
    }
  ],
  "examples": []
}
