Career Opportunities
    Find an Expert
    Insights & Analysis


Redis session store for Connect

3.4.2  •  Published 1 month ago  •  by TJ Holowaychuk  •  MIT License

npm Dependencies Downloads

connect-redis is a Redis session store backed by node_redis, and is insanely fast 😃. Requires redis >= 2.0.0 for the SETEX command.


npm install connect-redis express-session

Pass the express-session store into connect-redis to create a RedisStore constructor.

var session = require('express-session');
var RedisStore = require('connect-redis')(session);

    store: new RedisStore(options),
    secret: 'keyboard cat',
    resave: false


A Redis client is required. An existing client can be passed directly using the client param or created for you using the host, port, or socket params.

  • client An existing client
  • host Redis server hostname
  • port Redis server portno
  • socket Redis server unix_socket
  • url Redis server url

The following additional params may be included:

  • ttl Redis session TTL (expiration) in seconds. Defaults to session.cookie.maxAge (if set), or one day.
    • This may also be set to a function of the form (store, sess, sessionID) => number.
  • disableTTL Disables setting TTL, keys will stay in redis until evicted by other means (overides ttl)
  • db Database index to use. Defaults to Redis’s default (0).
  • pass Password for Redis authentication
  • prefix Key prefix defaulting to “sess:”
  • unref Set true to unref the Redis client. Warning: this is an experimental feature.
  • serializer An object containing stringify and parse methods compatible with Javascript’s JSON to override the serializer used
  • logErrors Whether or not to log client errors. (default: false)
    • If true, a default logging function (console.error) is provided.
    • If a function, it is called anytime an error occurs (useful for custom logging)
    • If false, no logging occurs.
  • scanCount Value used for count parameter in Redis SCAN command (used in ids() and all() methods, defaults to 100).

Any options not included in this list will be passed to the redis createClient() method directly.

Custom Redis clients

Clients other than node_redis will work if they support the same interface. Just pass the client instance as the client configuration option. Known supported clients include:

  • ioredis - adds support for Redis Sentinel and Cluster

Testing / Development

You can use redis-mock as the client instead of connecting to an actual redis server for automated testing and development purposes.


How do I handle lost connections to Redis?

By default, the node_redis client will auto-reconnect when a connection is lost. But requests may come in during that time. In Express, this scenario can be handled by including a “session check”.

app.use(session( /* setup session here */ ))
app.use(function (req, res, next) {
  if (!req.session) {
    return next(new Error('oh no')) // handle error
  next() // otherwise continue

If you want to retry, here is another option.




debug  ·  redis  ·  blue-tape  ·  bluebird  ·  eslint  ·  express-session  ·  ioredis  ·  istanbul  ·  sinon  ·  tape
Get an open source license report with a click
Whether it's for legal, customers or investors, upload your package.json files, and get a comprehensive license report page and spreadsheet. No hassle, it just works!
$49 one time fee, money back guarantee


Weekly Downloads

Issues and PRs


Last ver 1 month ago
Created 9 years ago
Last commit 1 month ago
13 days between commits


52 contributors


Node version: 10.16.0
24.7K unpacked

Legal and Compliance

MIT License
OSI Approved
0 vulnerabilities

Top Experts

Tj Holowaychuk
Maintainer, 109 commits, 12 merges
Works at Apex
Marc Harter
Maintainer, 75 commits, 30 merges
Works at applieddataconsultants
Maintainer, 12 commits, 2 merges
Lakshmikantan G
9 commits
Louis Chatriot
5 commits, 2 PRs
Works at Stripe
4 commits, 3 PRs
Works at Red Comet Labs