Redis发布订阅和Socket.IO

huangapple go评论72阅读模式
英文:

Redis pub sub and socket io

问题

我对Redis实际上很新。那么,当你有Socket.IO时,Redis发布/订阅的目的是什么?比如对于聊天应用,Socket.IO用于用户从客户端发送消息到服务器,然后服务器将消息发送给用户,根据其套接字ID进行发送。那么在这种情况下,Redis发布/订阅有什么用途?

假设我有一个客户端,Redis可以向其发送事件吗?

我有点困惑。

谢谢,

英文:

I am actually new to redis . So what is the purpose of redis pub sub when you have socket io ? So lets say for a chat app, socket io is used for users to send message from client to server then the server will take the message and emit it to the user based on its socket id. So what is redis pub sub used for in this instance ?

Lets say I have a client, can redis emit events to it ?

I am kinda confused.

Thank you,

答案1

得分: 2

Redis pub sub用于在有多个服务器或进程与客户端连接时使用。

如果服务器/进程A接收到需要发送给连接到服务器/进程B的客户端B的消息,那么如何仅使用socket.io来完成呢?这就是Redis pub sub发挥作用的地方。服务器A发布一条消息,服务器B接收到后将其转发给客户端B。

英文:

Redis pub sub is used when you have more than 1 server or process to which the clients are connected.

If server/process A receives a message that needs to be sent to client B who is connected to server/process B - how would you do that with just socket io? This is where redis pub sub comes in. Server A does a pub that server B receives which then forwards it on to client B

huangapple
  • 本文由 发表于 2023年4月10日 21:36:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977606.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定