about:benjie

Random learnings and other thoughts from an unashamed geek

NodeJS: Express/Socket.io/RedisStore Headache

| Comments

If you’re trying to access a session from a socket.io socket, I recommend following these instructions which work great for MemoryStore. However for RedisStore you need to do a little more work because the object returned is just a JSON object - not a Session object as it should be. I’ve hacked around it by adding the following (CoffeeScript) to convert it to a Session object if required:

.coffee.jsMake sure ‘session’ is a Session object
1
2
3
4
5
if session and not session.prototype?.reload
    req =
        sessionStore: sessionStore
        sessionID: data.sessionID
    session = new express.session.Session req, session

immediately inside the sessionStore.get callback.

Comments