Currently I am using node.js and redis to build a app, the reason I use redis is because of the publish/subscribe feature. The app is simply to notify the manager when user comes into the user or out of room.
function publishMsg( channel , mssage){
redisClient.publish(channel,JSON.stringify());
}
publishMsg('room/1/user/b',{'room':1,'user':'b'});
publishMsg('room/1/user/c',{'room':1,'user':'c'});
publishMsg('room/2/user/b',{'room':2,'user':'b'});
publishMsg('room/2/user/c',{'room':2,'user':'c'});
function subscribe(pattern){
redisClient.psubscribe(pattern);
redisClient.on('pmessage', function(pattern, channel, message){
console.log('on publish / subscribe ', pattern+" "+channel+" "+message+" "+ JSON.parse( message) );
});
}
since I want to listen to the join and disjoin event, my question is should I use two redisclient to listen these two events, like
redisClient1.psubscribe('room/*/user/*/join');
redisClient2.psubscribe('room/*/user/*/disjoin');
or just use one redisclient to listen and seperate the logic inside the callback
redisClient2.psubscribe('room/*/user/*');
I know these two ways are possible, But I don't know how in reality people use them, in which condition?