如果我有多个进程并且正在使用 socket.io-redis,那么当我这样做时,io.to(room).emit(namespace, message);
这是否可以无缝且高效地处理?还是我误解了socket.io-redis的作用?
问问题
3508 次
1 回答
3
嗨,简而言之,据我所知,这是-
io.to('room').emit('namespace', 'message');
意思是,向'room'通道中的所有客户端(包括发送者)发送具有值'message' 的message
命名'namespace' 。
详细信息(在此处找到)-
// 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
更多可以在这里找到。
基本的-
实际上问题是您的问题是如此之类,以至于其他人很难理解您到底需要什么。所以,我假设你也需要知道这背后的基本概念。所以我添加这部分也是为了你的信息。
socket.io和Redis的概念是你应该管理与套接字的连接并将数据作为数据库存储在 redis 中。
Redis通常用于在 DB(或缓存数据库)上应用层,以便可以将某些数据存储一段时间。所以在那段时间之间,如果需要任何查询,数据将来自 Redis,而不是来自 DB 查询。
该系统用于性能调整,以便您的系统可以同时处理巨大的负载。
在您的情况下,您可以在短时间内缓存数据,以便通过socket.io发送消息。
更多可以在这里找到-
认为这个答案肯定会帮助你。
于 2016-04-10T08:54:15.313 回答