扩展表达/节点。js和套接字。io水平与复述,

时间:2022-08-22 15:48:14

I am trying to scale by express backend. The problem is that every time a user comes in or if I restart the server it gets a new socket.id. Plus I can't save the whole socket into memory because it gives me a [Circular JSON] problem. How do I save somepart of the socket into redis that will allow me retrieve the same socket from other servers?

我正试图通过后端快速扩展。问题是每当用户进来或者我重新启动服务器时,它都会得到一个新的socket.id。另外,我不能将整个套接字保存到内存中,因为这会给我带来一个[循环JSON]问题。如何将套接字的某些部分保存到redis中,以便从其他服务器检索相同的套接字?

1 个解决方案

#1


4  

You need to decouple the user from the socket.id. The socket.id is volatile and can change even with a browser refresh. Instead, when a user socket connects, take a look at the handshake data which is passed and use that to associate the socket to the user. As far as persisting socket data in redis, that can already be handled for you using socket.io-redis.

您需要将用户与socket.id解耦。套接字。id是不稳定的,甚至可以通过浏览器刷新来更改。相反,当用户套接字连接时,查看传递的握手数据,并使用它将套接字与用户关联。至于在redis中持久化套接字数据,已经可以使用socket.io-redis进行处理了。

Take a look at this link for scaling out socket.io: http://socket.io/docs/using-multiple-nodes

看一下这个链接,用于扩展套接字。io:http://socket.io/docs/using-multiple-nodes

#1


4  

You need to decouple the user from the socket.id. The socket.id is volatile and can change even with a browser refresh. Instead, when a user socket connects, take a look at the handshake data which is passed and use that to associate the socket to the user. As far as persisting socket data in redis, that can already be handled for you using socket.io-redis.

您需要将用户与socket.id解耦。套接字。id是不稳定的,甚至可以通过浏览器刷新来更改。相反,当用户套接字连接时,查看传递的握手数据,并使用它将套接字与用户关联。至于在redis中持久化套接字数据,已经可以使用socket.io-redis进行处理了。

Take a look at this link for scaling out socket.io: http://socket.io/docs/using-multiple-nodes

看一下这个链接,用于扩展套接字。io:http://socket.io/docs/using-multiple-nodes