如果我有多个进程,并且正在使用socket.io-redis,那么当我执行io.to(room).emit(namespace, message);时,这是无缝和高效的处理吗?还是我误解了Socket.IO-redis的角色?
发布于 2016-04-10 08:54:15
总之,据我所知这是-
io.to('room').emit('namespace', 'message');这意味着将名为message的‘命名空间’和值‘消息’发送给'room'通道中的所有客户端,包括发送方。
详细信息(见于这里)-
// 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的概念是u应该管理与套接字的连接,并将数据以DB的形式存储在redis中。
Redis通常用于在DB上应用层(或缓存数据库),以便某些数据可以存储一个时间间隔。因此,在此期间,如果需要任何查询,数据将来自Redis,而不是DB查询。
该系统适用于性能调优,以便您的系统能够同时处理巨大的负载。
在您的示例中,您可以将数据缓存一段很短的时间间隔,以便通过socket.io发送消息。
在这里可以找到更多-
相信这个答案一定会对你有帮助。
https://stackoverflow.com/questions/36367453
复制相似问题