Search code examples
node.jsredissocket.ioreal-time

socket.io determine if a user is online or offline. Should I store the data in a database?


I was going through this question: socket.io determine if a user is online or offline.

In the answer I have seen that an object containing the online users is created. In a production app should you store this data in a database like redis? Or is it okay if it stays saved in memory in the server?


Solution

  • I would not store the users in the server's memory, imagine this case:

    for some reason you need to restart the server, a crash, a new version update, a new release and the memory of the server gets reset and you loose the users object.

    So for this redis looks like a great option to store users data.