Socket
Socket
Sign inDemoInstall

connect-redis

Package Overview
Dependencies
0
Maintainers
3
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.1.3 to 7.0.0-rc.1

index_test.ts

56

package.json
{
"name": "connect-redis",
"description": "Redis session store for Connect",
"version": "6.1.3",
"version": "7.0.0-rc.1",
"author": "TJ Holowaychuk <tj@vision-media.ca>",

@@ -10,31 +10,47 @@ "contributors": [

"license": "MIT",
"main": "./index.js",
"main": "./dist/esm/index.js",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
}
},
"types": "./dist/esm/index.d.ts",
"scripts": {
"prepublishOnly": "rm -rf dist && tsc & tsc --project tsconfig.esm.json && echo '{\"type\":\"module\"}' > dist/esm/package.json",
"build": "npm run prepublishOnly",
"test": "nyc ts-node node_modules/blue-tape/bin/blue-tape \"**/*_test.ts\"",
"lint": "tsc --noemit && eslint --max-warnings 0 --ext ts testdata *.ts",
"fmt": "prettier --write .",
"fmt-check": "prettier --check ."
},
"repository": {
"type": "git",
"url": "git@github.com:visionmedia/connect-redis.git"
"url": "git@github.com:tj/connect-redis.git"
},
"devDependencies": {
"@types/blue-tape": "^0.1.33",
"@types/express-session": "^1.17.6",
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"blue-tape": "^1.0.0",
"eslint": "^7.4.0",
"eslint-config-prettier": "^8.3.0",
"express-session": "^1.17.0",
"ioredis": "^4.17.1",
"nyc": "^15.0.1",
"prettier": "^2.0.5",
"redis-mock": "^0.56.3",
"redis-v3": "npm:redis@3",
"redis-v4": "npm:redis@4"
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"express-session": "^1.17.3",
"ioredis": "^5.3.1",
"nyc": "^15.1.0",
"prettier": "^2.8.4",
"prettier-plugin-organize-imports": "^3.2.2",
"redis": "^4.6.4",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"engines": {
"node": ">=12"
"node": ">=16"
},
"bugs": {
"url": "https://github.com/visionmedia/connect-redis/issues"
"url": "https://github.com/tj/connect-redis/issues"
},
"scripts": {
"test": "nyc tape \"test/*-test.js\"",
"lint": "eslint index.js test lib",
"fmt": "prettier --write .",
"fmt-check": "prettier --check ."
},
"keywords": [

@@ -41,0 +57,0 @@ "connect",

![Build Status](https://github.com/tj/connect-redis/workflows/build/badge.svg?branch=master) [![npm](https://img.shields.io/npm/v/connect-redis.svg)](https://npmjs.com/package/connect-redis) [![code-style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://gitter.im/jlongster/prettier) ![Downloads](https://img.shields.io/npm/dm/connect-redis.svg)
**connect-redis** provides Redis session storage for Express. Requires Redis >= `2.0.0`.
**connect-redis** provides Redis session storage for Express.
## Installation
npm:
**connect-redis** requires `express-session` to installed and one of the following compatible Redis clients:
- [`redis`][1]
- [`ioredis`][2]
Install with `redis`:
```sh

@@ -13,33 +18,50 @@ npm install redis connect-redis express-session

Yarn:
Install with `ioredis`:
```sh
yarn add redis connect-redis express-session
npm install ioredis connect-redis express-session
```
## Importing
**connect-redis** supports both CommonJS (`require`) and ESM (`import`) modules.
Import using ESM/Typescript:
```js
import RedisStore from "connect-redis"
```
Require using CommonJS:
```js
const RedisStore = require("connect-redis").default
```
## API
Full setup using [`redis`][1] package:
```js
const session = require("express-session")
let RedisStore = require("connect-redis")(session)
import RedisStore from "connect-redis"
import session from "express-session"
import {createClient} from "redis"
// redis@v4
const { createClient } = require("redis")
let redisClient = createClient({ legacyMode: true })
// Initialize client.
let redisClient = createClient()
redisClient.connect().catch(console.error)
// redis@v3
const { createClient } = require("redis")
let redisClient = createClient()
// Initialize store.
let redisStore = new RedisStore({
client: redisClient,
prefix: "myapp:",
})
// ioredis
const Redis = require("ioredis")
let redisClient = new Redis()
// Initialize sesssion storage.
app.use(
session({
store: new RedisStore({ client: redisClient }),
saveUninitialized: false,
store: redisStore,
resave: false, // required: force lightweight session keep alive (touch)
saveUninitialized: false, // recommended: only save session when data exists
secret: "keyboard cat",
resave: false,
})

@@ -51,4 +73,2 @@ )

The `RedisStore` requires an existing Redis client. Any clients compatible with the [`redis`][1] API will work. See `client` option for more details.
#### Options

@@ -58,10 +78,4 @@

An instance of [`redis`][1] or a `redis` compatible client.
An instance of [`redis`][1] or [`ioredis`][2].
Known compatible and tested clients:
- [redis][1] (v3, v4 with `legacyMode: true`)
- [ioredis](https://github.com/luin/ioredis)
- [redis-mock](https://github.com/yeahoffline/redis-mock) for testing.
##### prefix

@@ -71,3 +85,3 @@

This prefix appends to whatever prefix you may have set on the `client` itself.
**Note**: This prefix appends to whatever prefix you may have set on the `client` itself.

@@ -84,11 +98,11 @@ **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.

**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.
**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_.
##### disableTouch
Disables re-saving and resetting the TTL when using `touch` (default: `false`)
Disables resetting the TTL when using `touch` (default: `false`)
The `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.
Ref: https://github.com/expressjs/session#storetouchsid-session-callback
Ref: <https://github.com/expressjs/session#storetouchsid-session-callback>

@@ -99,7 +113,9 @@ ##### disableTTL

This 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. Note this has no effect on `express-session` setting cookie expiration.
This 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.
**Note**: This has no effect on `express-session` setting cookie expiration.
##### serializer
The encoder/decoder to use when storing and retrieving session data from Redis (default: `JSON`).
Provide a custom encoder/decoder to use when storing and retrieving session data from Redis (default: `JSON.parse` and `JSON.stringify`).

@@ -127,3 +143,3 @@ ```ts

By default, the [`redis`][1] client will [auto-reconnect](https://github.com/mranney/node_redis#overloading) on lost connections. But requests may come in during that time. In Express, one way you can handle this scenario is including a "session check":
By default, the Redis client will [auto-reconnect](https://github.com/mranney/node_redis#overloading) on lost connections. But requests may come in during that time. In Express, one way you can handle this scenario is including a "session check":

@@ -143,1 +159,2 @@ ```js

[1]: https://github.com/NodeRedis/node-redis
[2]: https://github.com/luin/ioredis

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc