Express + Passport + Redis sessions?

To date I have been using the default MemoryStore for my Express sessions. Everything has been working great, except that all session data is lost between restarts. So I am trying to get my sessions working with Redis & Connect-Redis instead.

Here is the part of my code that concerns session config with Redis:

var express = require( "express" ),
    app = module.exports = express(),
    passport = require( "./passport" ),
    http = require( "http" ),
    RedisStore = require( "connect-redis" )( express ),
    redis = require( "redis" ).createClient();

app.configure(function(){

    app.set( "passport", passport );
    app.use( express.cookieParser());
    app.use( express.session({
         secret: "I can haz working sessions?",
         store: new RedisStore({ client: redis })
    }));
    app.use( passport.initialize() );
    app.use( passport.session() );
    ...

When I run this application, there are no errors. However when I try to login, although it performs the initial login, I just keep getting bounced back to the login screen. It is as if passport cannot set a cookie, or cannot read a cookie after it has been set.

For reference, here are the functions I use in passport to serialize / deserialize the session:

passport.serializeUser(function( user, done ) {
    done( null, {
        id : user.id,
        type : user.type,
        firstname: user.firstname,
        lastname: user.lastname
    });
});

passport.deserializeUser(function( user, done ) {
    done( null, user );
});

Any advice on where I am going wrong? Do the passport serializeUser / deserializeUser need to be modified to work with redis? Or am I missing something else?

Thanks (in advance) for your help.

One possibility: maybe your app can't connect to Redis? I found that when my redis-server was not running, I experienced the symptom you describe (silently fails to set cookies).

Aside from checking that it's running, make sure your Node server can actually connect to it—that is, that there are no firewall rules keeping you out.

Good luck!