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?
Asked
Active
Viewed 2,108 times
1 Answers
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.
Take a look at this link for scaling out socket.io: http://socket.io/docs/using-multiple-nodes

Timothy Strimple
- 22,920
- 6
- 69
- 76
-
I have socket.io-redis running but there seems to be little to no documentation about how to use it. Have any links that may help? – Ridan Dec 12 '14 at 01:45
-
There shouldn't be anything to using it. Once it's setup, it exists in the background and ensures your various socket.io nodes are able to communicate with each other. Setup is pretty simple: https://github.com/Automattic/socket.io-redis – Timothy Strimple Dec 12 '14 at 02:07