{"id":15369615,"url":"https://github.com/rahil-p/connect-redis-session","last_synced_at":"2026-01-05T13:02:11.363Z","repository":{"id":38352052,"uuid":"451658188","full_name":"rahil-p/connect-redis-session","owner":"rahil-p","description":"Redis session storage for Node.js and Express.js","archived":false,"fork":false,"pushed_at":"2023-01-07T19:23:33.000Z","size":506,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T07:11:53.270Z","etag":null,"topics":["express","lua","node","redis","session","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rahil-p.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-24T22:42:59.000Z","updated_at":"2022-09-12T03:51:50.000Z","dependencies_parsed_at":"2023-02-07T22:35:14.849Z","dependency_job_id":null,"html_url":"https://github.com/rahil-p/connect-redis-session","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahil-p%2Fconnect-redis-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahil-p%2Fconnect-redis-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahil-p%2Fconnect-redis-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahil-p%2Fconnect-redis-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rahil-p","download_url":"https://codeload.github.com/rahil-p/connect-redis-session/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244898458,"owners_count":20528341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","lua","node","redis","session","typescript"],"created_at":"2024-10-01T13:37:01.125Z","updated_at":"2026-01-05T13:02:11.271Z","avatar_url":"https://github.com/rahil-p.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# connect-redis-session\n\nRedis session storage for Express supporting the latest [`node-redis`][node-redis] client.\n\n[![npm](https://img.shields.io/npm/v/connect-redis-session?logo=npm)](https://www.npmjs.com/package/connect-redis-session)\n[![codecov](https://codecov.io/gh/rahil-p/connect-redis-session/branch/main/graph/badge.svg?token=P0nIvyEnTS)](https://codecov.io/gh/rahil-p/connect-redis-session)\n[![github-workflow](https://img.shields.io/github/workflow/status/rahil-p/connect-redis-session/npm%20publish?logo=github)](https://github.com/rahil-p/connect-redis-session/actions)\n\n___\n\n### Features:\n\n- Promise-based methods for direct interaction with the sessions store\n- Atomic single-key operations (`get`, `set`, `touch`, `destroy`)\n- Batched multi-key operations (`all`, `length`, `clear`) for efficient performance\n- Safeguards for handling race conditions caused by concurrent requests\n- First class support for [Typescript](https://www.typescriptlang.org/)\n\n\n### Compatibility:\n\n- Redis server 2.6.0+\n- [`node-redis`][node-redis] 4.0.0+\n- [`express-session`][express-session] 1.17.0+\n\n___\n\n## Installation\n```shell\nnpm install connect-redis-session # redis@^4 express-session@^1.17\n```\n\n```shell\nyarn add connect-redis-session # redis@^4 express-session@^1.17 \n```\n\n\n\n## Usage\n\n### Quick Start\n```js\nconst session = require('express-session');\nconst redis = require('redis');\nconst { RedisStore } = require('connect-redis-session');\n\n// Create the Redis client\nconst client = redis.createClient();\n\n// Configure the Redis store\nconst store = new RedisStore({ client });\n\n// Configure the Express session middleware\napp.use(\n    session({\n        store,\n        secret: 'swordfish',\n        saveUninitialized: false, // recommended\n        resave: false, // recommended\n        // ...\n    }),\n);\n```\n\n### Access with Promises\n\nThe `RedisStore.access` field exposes methods for directly interacting with the store using Promises.\n\n```js\nconst updateSession = async (sid) =\u003e {\n    // Get a session from the store\n    const session = await store.access.get(sid);\n\n    // Create or update a session\n    await store.access.set(sid, { ...session, foo: 'bar' })\n\n    // Delete a session\n    await store.access.destroy(sid);\n\n    // Get all sessions\n    const sessions = await session.access.all();\n\n    // Count all sessions\n    const n = await session.access.length();\n\n    // Clear all session keys from the store\n    await store.access.clear();\n}\n```\n\n## Options\n\n```js\nconst store = new RedisStore({\n    client,\n    prefix: 'sessions:',\n    scanCount: 100,\n    ttlSeconds: 86400,\n    concurrencyGraceSeconds: 300,\n    disableTouch: false,\n})\n```\n\n___\n\n### `client`\n\nobject | **required**\n\nAn initialized [`node-redis`][node-redis] v4 client.\n\nPrior to server listening, the client's `connect` method should be called.\n\n\u003cdetails\u003e\n\n\u003csummary\u003eexample\u003c/summary\u003e\n\n```js\n(async () =\u003e {\n    await client.connect();\n    server.listen(80);\n})();\n```\n\n\u003c/details\u003e\n\n___\n\n### `prefix`\n\nstring • `'sessions:'`\n\nA prefix used for each key in the session store.\n\n___\n\n### `scanCount`\n\nnumber • `100`\n\nThe maximum number of keys batched in Redis `SCAN` calls.  This also helps limit the memory load on subsequent calls\nusing the key batches (e.g. `MGET`, `DEL`).\n\n___\n\n### `ttlSeconds`\n\nnumber | `false` • `86400` _1 day_\n\nThe fallback duration in\nseconds after which a created or updated session should be expired.\n\nThis field is only used when a session is missing the\n[`cookie.expires`](https://github.com/expressjs/session#cookieexpires) field.\n\nWhen set to `0` or `false`, the store will reject sessions missing the\n[`cookie.expires`](https://github.com/expressjs/session#cookieexpires) field.\n\n___\n\n### `concurrencyGraceSeconds`\n\nnumber • `300`\n\nThe duration in seconds after [tombstone](https://en.wikipedia.org/wiki/Tombstone_(data_store)) records are removed from\nthe store.\n\nTombstone records are used to prevent a destroyed session from being updated or touched. This lock is retained for the \nduration specified by this setting.\n\n___\n\n### `disableTouch`\n\nboolean • `false`\n\nDisables renewing the session's time to live when the session's [`touch`](https://github.com/expressjs/session#sessiontouch)\nmethod is used.\n\nSetting this option to `true` is not recommended and should share the same value as the session's\n[`resave`](https://github.com/expressjs/session#saveuninitialized)\noption.\n\n___\n\n### `serializer`\n\nobject\n\nA custom serializer implementing the following encoding and decoding methods for storing session data as Redis string\nvalues:\n\n- `stringify`: `(value: SessionData) =\u003e string`\n- `parse`: `(text: string) =\u003e SessionData`\n\nRefer to the global [`JSON`][mdn-json] object for an example.\n\n___\n\n## License\n[MIT License](https://github.com/rahil-p/connect-redis-session/blob/master/LICENSE)\n\n[node-redis]: https://github.com/redis/node-redis\n[express-session]: https://github.com/expressjs/session\n[mdn-json]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahil-p%2Fconnect-redis-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frahil-p%2Fconnect-redis-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahil-p%2Fconnect-redis-session/lists"}