Redis Pub-Sub or Socket.IO's broadcast

前端 未结 2 473
北恋
北恋 2020-12-25 15:34

I saw this snippet:

On Server

io.sockets.on(\'connection\', function(socket) {
  const subscribe = redis.createClient();
  const publish = redis.cr         


        
2条回答
  •  失恋的感觉
    2020-12-25 15:41

    The reason I chose to use Redis Pub Sub with Socket.io in my Real Time Activity Stream project (http://blog.cloudfoundry.com/2012/06/05/node-activity-streams-app-2/) was because I wanted to have multiple web servers (instances on Cloud Foundry or dynos on Heroku). As far as I could see, Socket.io stores the messages in memory (of one webserver), so how it could possibly broadcast to clients which are connected to another webserver?

    Check out the post and let me know if it helps

提交回复
热议问题