Get the Socket object by ID using node, redis-adapter and socket.io

I am creating a real time web game with nodejs and socket.io. I use redis-adapter and sticky sessions so that I can start the cluster.

My problem is that I need to get the client socket object using its identifier. I do not know how I can do this! HERE is the native socket.io solution, but it only works in non-cluster mode. It is strange that the redis adapter does not implement this functionality!

I could (using node -redis ) save the entire socket object of all clients in redis LIST and get it when I do, but I don't like it. Why do I need to save for each client the entire socket object in redis, when I could only save the socket id? In any case, this solution cannot work, because when I try to save the socket object in redis, I have this error:

converting circular structure to JSON

therefore, it seems that sockets have the inverse structure, and they cannot be stored in redis as a string (using JSON.stringify (socket)).

So the thing is, as I say: I need a socket object of a specific client using the socket identifier. I cannot manually save all client socket objects in redis, and redis-adapter for the io socket does not seem to perform this function. How can i do this?

+4

All Articles