Answer the question
In order to leave comments, you need to log in
How to store socket'a id in database to send messages?
Greetings. The problem is this - with each connection to the Socket.IO server, a unique ID is created for the client at the moment of handshake, in order to send a message to this client - you need to know its id.
How to be? To write down it in basis at each connection?
My only idea is to make something like users_online in Redis and store it as user_id => socket_id. In Redis, because it works in memory, so all calls to it will be faster.
PS Redis saves data to disk periodically, how can it be Only-Memory?
Answer the question
In order to leave comments, you need to log in
No need to store in databases, store in memory, the node is also always in memory, it is not necessary to access an external process such as a radish. If the process is parade, then its connections also fall and these IDs are no longer needed by anyone. If there are several processes, then use message buses, ZeroMQ, RabbitMQ, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question