What should I be using? Socket.io rooms or Redis pub-sub?

前端 未结 2 417
Happy的楠姐
Happy的楠姐 2020-12-12 11:52

Pretty simple question. I am building a realtime game using nodejs as my backend and I am wondering if there is any information available on which one is more reliable and w

2条回答
  •  醉酒成梦
    2020-12-12 12:12

    Redis pub/sub is great in case all clients have direct access to redis. If you have multiple node servers, one can push a message to the others.

    But if you also have clients in the browser, you need something else to push data from a server to a client, and in this case, socket.io is great.

    Now, if you use socket.io with the Redis store, socket.io will use Redis pub/sub under the hood to propagate messages between servers, and servers will propagate messages to clients.

    So using socket.io rooms with socket.io configured with the Redis store is probably the simplest for you.

提交回复
热议问题