Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

req.session undefined with Redis/Express

req.session undefined with Redis/Express


I switched from memorystore to using Redis and I also use MongoDB locally.

Similar posts that I have read are not relevant or helpfull. Basicly, if the router function try's to set a value to req.session the node app shuts down.

I am new to Redis, so maybe it is something obvious that I don't see?

// in app
var app = express();
var cookieParser = express.cookieParser('secret');
app.configure(function () {
  app.use(express.session({secret: 'secret', store: othermodule.getSessionStore()})); 

// othermodule
var RedisStore = require('connect-redis')(express);  
var sessionStore = new RedisStore({
    host: 'localhost',
    port: 6379,
    db: 2,
    pass: 'RedisPASS'});


Problem courtesy of: Richard


Try removing the Password in your options you pass to RedisStore.

If you want you can require the clients to give a password when connecting. But by default no password is required for clients to connect. If no password is required and you give a password, the client will try authenticating using the given password which will cause a connection failure. The fallback to using no password is not allowed at the client. Because of which you were getting session as undefined.

See here and here for configuring passwords.

Solution courtesy of: user568109


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

req.session undefined with Redis/Express


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription