Scaling Socket.IO across multiple servers

前端 未结 1 998
暖寄归人
暖寄归人 2021-02-14 02:22

I\'ve been searching around looking for help on setting up a multi-server cluster for a Node.js Socket.IO install. This is what I am trying to do:

  • Have 1 VIP in an
1条回答
  •  温柔的废话
    2021-02-14 02:38

    The answer to this question is that you must set up a single Redis server that is either outside your SocketIO cluster - and have all nodes connect to it.

    Then you simply add this at the top of your code and it just works magically without any issues.

    var io = require('socket.io')(server);
    var redis = require('socket.io-redis');
    io.adapter(redis({ host: 'localhost', port: 6379 }));
    

    0 讨论(0)
提交回复
热议问题