elad / node-cluster-socket.io

Writeup on how to make node.js cluster and socket.io play nice
421 stars 63 forks source link

What's the role of radis in the cluster? #13

Closed needforspeed closed 8 years ago

needforspeed commented 8 years ago

Can I just use a map in master of the cluster for the key value pair instead? If so, can you please share some code for such? Especially on the adapter part, I didn't find much document on the adapter.

Thank you in advance!

lricoy commented 8 years ago

The Redis adapter is used to emit/broadcast messages to all workers. If not used, the messages would be sent only to the clients connected to that specific worker.

Imagine the following scenario:

Client A ----> Worker 1 Client B ----> Worker 2 Client C ----> Worker 1

The Redis adapter allows you to send a message to all clients by using Redis's Pub/Sub mechanism. Otherwise, if you started your broadcast from the Worker 2, only Client B would receive the message.

elad commented 8 years ago

Forgot about this. No, you can't. Different processes don't share address space so your map would be local to the master and invisible to the workers.