Get Socket Object by Id with node, redis-adapter and socket.io

900 views Asked by At

I'm building a real time webgame with nodejs and socket.io. I'm using redis-adapter and sticky-sessions so i'll able to run a cluster.

My problem is I need to get the socket object of a client using his id. I dont know how i can do it! HERE there is a socket.io native solution but it works only in non-cluter mode. It's so strange that the redis-adapter is not implementing this functionality!

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

converting circular structure to JSON

so, it seems that sockets has a circluar structure, and they can't be stored in redis as a string (using JSON.stringify(socket) ).

So the point is, as i say: i need the socket object of a specific client using the socket id. I can't store manually all the clients socket object in redis and the redis-adapter for socket io seems is not implementing this functionality. How can i do?

0

There are 0 answers