{"id":13485211,"url":"https://github.com/tj/connect-redis","last_synced_at":"2025-05-13T17:04:12.542Z","repository":{"id":973397,"uuid":"771088","full_name":"tj/connect-redis","owner":"tj","description":"Redis session store for Connect","archived":false,"fork":false,"pushed_at":"2025-04-21T17:45:36.000Z","size":422,"stargazers_count":2816,"open_issues_count":4,"forks_count":349,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-05-06T16:14:39.731Z","etag":null,"topics":[],"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/tj.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2010-07-12T19:47:08.000Z","updated_at":"2025-04-29T02:46:03.000Z","dependencies_parsed_at":"2023-02-17T23:15:35.736Z","dependency_job_id":"e9ef5ced-ef8a-42a5-981d-cdc5652b2e0e","html_url":"https://github.com/tj/connect-redis","commit_stats":{"total_commits":289,"total_committers":66,"mean_commits":4.378787878787879,"dds":0.6678200692041523,"last_synced_commit":"f390403456b1b35a6dca74b1c144f6deeca840cd"},"previous_names":["visionmedia/connect-redis"],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fconnect-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fconnect-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fconnect-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fconnect-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tj","download_url":"https://codeload.github.com/tj/connect-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253604345,"owners_count":21934844,"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":[],"created_at":"2024-07-31T17:01:51.092Z","updated_at":"2025-05-13T17:04:12.495Z","avatar_url":"https://github.com/tj.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Stale"],"sub_categories":["JS Libraries \u0026 Utilities"],"readme":"[![build](https://github.com/tj/connect-redis/actions/workflows/build.yml/badge.svg)](https://github.com/tj/connect-redis/actions/workflows/build.yml) [![npm](https://img.shields.io/npm/v/connect-redis.svg)](https://npmjs.com/package/connect-redis) ![Downloads](https://img.shields.io/npm/dm/connect-redis.svg)\n\n**connect-redis** provides Redis session storage for Express.\n\n## Installation\n\n**connect-redis** requires `express-session` to be installed and one of the following compatible Redis clients:\n\n- [`redis`][1]\n- [`ioredis`][2]\n\nInstall with `redis`:\n\n```sh\nnpm install redis connect-redis express-session\n```\n\nInstall with `ioredis`:\n\n```sh\nnpm install ioredis connect-redis express-session\n```\n\n## Importing\n\n**connect-redis** supports both CommonJS (`require`) and ESM (`import`) modules.\n\nImport using ESM/Typescript:\n\n```js\nimport {RedisStore} from \"connect-redis\"\n```\n\nRequire using CommonJS:\n\n```js\nconst {RedisStore} = require(\"connect-redis\")\n```\n\n## API\n\nFull setup using [`redis`][1] package:\n\n```js\nimport {RedisStore} from \"connect-redis\"\nimport session from \"express-session\"\nimport {createClient} from \"redis\"\n\n// Initialize client.\nlet redisClient = createClient()\nredisClient.connect().catch(console.error)\n\n// Initialize store.\nlet redisStore = new RedisStore({\n  client: redisClient,\n  prefix: \"myapp:\",\n})\n\n// Initialize session storage.\napp.use(\n  session({\n    store: redisStore,\n    resave: false, // required: force lightweight session keep alive (touch)\n    saveUninitialized: false, // recommended: only save session when data exists\n    secret: \"keyboard cat\",\n  }),\n)\n```\n\n### RedisStore(options)\n\n#### Options\n\n##### client\n\nAn instance of [`redis`][1] or [`ioredis`][2].\n\n##### prefix\n\nKey prefix in Redis (default: `sess:`).\n\n**Note**: This prefix appends to whatever prefix you may have set on the `client` itself.\n\n**Note**: You may need unique prefixes for different applications sharing the same Redis instance. This limits bulk commands exposed in `express-session` (like `length`, `all`, `keys`, and `clear`) to a single application's data.\n\n##### ttl\n\nIf the session cookie has a `expires` date, `connect-redis` will use it as the TTL.\n\nOtherwise, it will expire the session using the `ttl` option (default: `86400` seconds or one day).\n\n```ts\ninterface RedisStoreOptions {\n  ...\n  ttl?: number | {(sess: SessionData): number}\n}\n```\n\n`ttl` also has external callback support. You can use it for dynamic TTL generation. It has access to `session` data.\n\n**Note**: The TTL is reset every time a user interacts with the server. You can disable this behavior in _some_ instances by using `disableTouch`.\n\n**Note**: `express-session` does not update `expires` until the end of the request life cycle. _Calling `session.save()` manually beforehand will have the previous value_.\n\n##### disableTouch\n\nDisables resetting the TTL when using `touch` (default: `false`)\n\nThe `express-session` package uses `touch` to signal to the store that the user has interacted with the session but hasn't changed anything in its data. Typically, this helps keep the users session alive if session changes are infrequent but you may want to disable it to cut down the extra calls or to prevent users from keeping sessions open too long. Also consider enabling if you store a lot of data on the session.\n\nRef: \u003chttps://github.com/expressjs/session#storetouchsid-session-callback\u003e\n\n##### disableTTL\n\nDisables key expiration completely (default: `false`)\n\nThis option disables key expiration requiring the user to manually manage key cleanup outside of `connect-redis`. Only use if you know what you are doing and have an exceptional case where you need to manage your own expiration in Redis.\n\n**Note**: This has no effect on `express-session` setting cookie expiration.\n\n##### serializer\n\nProvide a custom encoder/decoder to use when storing and retrieving session data from Redis (default: `JSON.parse` and `JSON.stringify`).\n\nOptionally `parse` method can be async if need be.\n\n```ts\ninterface Serializer {\n  parse(string): object | Promise\u003cobject\u003e\n  stringify(object): string\n}\n```\n\n##### scanCount\n\nValue used for _count_ parameter in [Redis `SCAN` command](https://redis.io/commands/scan#the-count-option). Used for `ids()` and `all()` methods (default: `100`).\n\n[1]: https://github.com/NodeRedis/node-redis\n[2]: https://github.com/luin/ioredis\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fconnect-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftj%2Fconnect-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fconnect-redis/lists"}