0

I want to have 2 instances of the node server 'A' and 'B'.

'A' will push connected clients [socket.io is used] in a room.

'A' will publish an event to which 'B' is already subscribed.

On receiving that particular event from 'A', instance 'B' will broadcast a message in the given room. Want to use the Room feature of socket.io

Want to ask that, is it possible ? I am trying redis store, but not getting how to publish an event so that server 'B' will receive it.

1

1 Answer 1

1

you can run 2 instances of redis, one on server A and one on server B.

if you bind adresses on A to * or to 127.0.0.1,B's IP, you can ask the server B to be slave of A: slaveof <A ip adress> 6379

every publish made by A will be replicate To B , so you can listen on the B serveur to the channel and push that you want to the Room

For you information , you can start the server to test like this : On A :

redis-server --port 6391 --bind (B-IP) --bind 127.0.0.1

on B:

redis-server --port 6392 --slaveof (A-IP) 6391

i'm not fully tested this solution(only tested on local host for the twice server) , but that should work

if you want to take care of some keys you can use psubscribe with some "keys" as channel name. i done it like that before:

on A

publish "|key1=toto||key2=titi||key3=plop|" "nanana"

on B

PSUBSCRIBE "*|key2=titi|*"

as you see separator on the key , you will have only the filtering push

you can do something like that in your node/socketIo : on A

var redis = require("redis");
client = redis.createClient();
client.publish("room::"+roomID, message);

on B

var redis = require("redis");
client = redis.createClient();
client.on("pmessage", function (pattern,channel, message){
    //emit on roomid(in channel) the message
}
client.psubscribe("room::*");

not tested...

Sign up to request clarification or add additional context in comments.

12 Comments

thanks for the reply, If i want to run node instances on same server then in that case, redis client in process A and redis client in process B should talk to each other, right ? And is redis-store helpful in anycase ?
it's more easy/secure to run them on same server , the bind adress is on 127.0.0.1 so safer. everything happenind on A is replicate on B pub/sub, key,list, etc.... I'm very fan of redis because is fast and persistable with some pub/sub inside and scripting in lua also . a lot of design is possible some use of case here :redis.io/documentation
roger that, trying that now
thanks, slave is receiving master's events. Now need to implement this through node.
may be this github.com/mranney/node_redis . Redis protocol is very simple
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.