How to setup Redis for sessions on an Expressjs application

Bahadir Balban

Started Tech Buzz


(source: Redis is a trademark of redis labs

Here is how you do it:

var redis_config = config.redis;
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var redis = require('redis');
var client = redis.createClient(redis_config.port,;
// These 3 has to be declared in this order
    store: new RedisStore({
      port: redis_config.port,
      client: client,
      logErrors: true,
    secret: 'your-secret-goes-here',
    maxAge: + (15 * 86400 * 1000),
    saveUninitialized: false,
    resave: false,
    secure: false,


Note the order of app.use() statements for session and passportJS initialization.

As you may see, Redis usually only needs a hostname and port for establishing a connection.

Join The Discussion