connect-redis
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
express-session | 1.18.0 | 22.25 kB | MIT | prod peer |
Connect-Redis is a package that provides Redis session storage for Express, a popular Node.js framework. With Connect-Redis, you can store your Express server session data in a Redis database, making it accessible across multiple server instances, improving your app's scalability, and providing an extra layer of user-data persistence.
To use Connect-Redis as your Express session store, you'll need to install the package and a Redis driver such as redis
or ioredis
as well as express-session
. You can install these with npm using the following commands:
npm install redis connect-redis express-session
or
npm install ioredis connect-redis express-session
Then require or import the package in your app's configuration:
import RedisStore from "connect-redis"
or
const RedisStore = require("connect-redis").default
Set up and connect your Redis client:
import {createClient} from "redis"
let redisClient = createClient()
redisClient.connect().catch(console.error)
Initialize a new RedisStore with your client:
let redisStore = new RedisStore({
client: redisClient,
prefix: "myapp:",
})
Then use the store in your Express session setup:
import session from "express-session"
app.use(
session({
store: redisStore,
resave: false,
saveUninitialized: false,
secret: "keyboard cat",
})
)
The Connect-Redis documentation is available on the package's GitHub repository. Among other details, it provides guidelines for configuring the RedisStore, including how to set key prefixes, handle session data lifetime (TTL), use custom serializers, and manage store behavior such as touch sessions and key expiration.