If I have multiple processes and am using socket.io-redis, when I do io.to(room).emit(namespace, message);
is this handled seamlessly and efficiently? Or am I misunderstanding socket.io-redis's role?

- 22,495
- 29
- 154
- 227
-
From what they say http://socket.io/docs/using-multiple-nodes/#passing-events-between-nodes ( ... (or even everyone in a certain room) ... ), seems like. Best way to find out is to test ! – yachaka Apr 09 '16 at 08:31
1 Answers
Hi in short as far as I know about this is-
io.to('room').emit('namespace', 'message');
Means, sending message
named 'namespace' with value 'message' to all clients in 'room' channel, including sender.
Detail info (found in here)-
// send to current request socket client
socket.emit('message', "this is a test");// Hasn't changed
// sending to all clients, include sender
io.sockets.emit('message', "this is a test"); // Old way, still compatible
io.emit('message', 'this is a test');// New way, works only in 1.x
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");// Hasn't changed
// sending to all clients in 'game' room(channel) except sender
socket.broadcast.to('game').emit('message', 'nice game');// Hasn't changed
// sending to all clients in 'game' room(channel), include sender
io.sockets.in('game').emit('message', 'cool game');// Old way, DOES NOT WORK ANYMORE
io.in('game').emit('message', 'cool game');// New way
io.to('game').emit('message', 'cool game');// New way, "in" or "to" are the exact same: "And then simply use to or in (they are the same) when broadcasting or emitting:" from http://socket.io/docs/rooms-and-namespaces/
// sending to individual socketid, socketid is like a room
io.sockets.socket(socketid).emit('message', 'for your eyes only');// Old way, DOES NOT WORK ANYMORE
socket.broadcast.to(socketid).emit('message', 'for your eyes only');// New way
Even more can be found here.
Basic-
Actually the thing is your question is so sort that it is very difficult for others to understand what u exactly need. So, I assume u need to know basic concepts behind this also. So I am adding this part also for your kind info.
The concept here with socket.io with Redis is u should manage connection with socket and store the data in redis as DB.
Redis normally used for applying a layer upon DB (or caching database) so that some data can be stored for a time interval. So between that time, if any query is needed, data will come from Redis, not from DB query.
This system is applied for performance tuning so that your system can handle a huge load at the same time.
In your case, u can cache data for a short time interval for sending the messages through socket.io.
More can be found here-
Think this answer will surely help u.

- 1
- 1

- 13,970
- 24
- 112
- 161
-
2that is the general concept of rooms in socket.io, but doesn't address the capabilities of the socket.io-redis module. – John Bachir Apr 11 '16 at 20:47
-
Actually the concept here with socket.io with redis is u should manage connection with socket and store the data in redis as DB – Abrar Jahin Apr 12 '16 at 07:11