Node.js: session can't be updated inside of redis pubsub event?

I'm trying to develop an node.js app that pass messages between backend processes and node using redis.

I want to be able to save in the user session (connect session) indicator that the message was received.

When the user performs ajax query "IsMessageRecieved" i want to return him the value I places in the session.

I tried to do it with the following code without luck, the session does not being updated.

redisSub.on("message", (channel, connectsid) ->
  sessionStore.get connectsid, (err, session) ->
    if (err || !session)
      return
    else
      session.MessageRecieved = true
      redisSub.unsubscribe('USER_DATA_READY_' + connectsid)
      return
  return
)

Do you know what might be the problem?

Thanks, Lior

I simplified your example to:

var redisSub = require('redis').createClient();
redisSub.subscribe('USER_DATA_READY_abc');
redisSub.on("message", function(channel, connectsid) {
    console.log(channel, connectsid);
});

And then ran redis-cli to publish manually to the channel, with the value "abc".

~ % redis-cli
redis 127.0.0.1:6379> publish USER_DATA_READY_abc abc
(integer) 1

And got the expected output of:

USER_DATA_READY_abc abc

Here is what I suggest

  • Make sure the on("message") is actually being called by adding a logging message.
  • Manually publish an existing session using redis-cli and see if that triggers any result in your callback.

I suspect the publish is not being made, or perhaps you're not subscribed to the right channel.