Reputation: 2269
I'm planning to store the messages (chat messages) on redis, and I stumbled upon a library socket.io-redis created by the socket.io people. I just want to know If I use this library what it will do to my current socket.io instance?
Will it automatically save all of the messages behind the scene?
For example, the only codes that I need to implement redis on top of my socket.io by using socket.io-redis
are
var redis = require('socket.io-redis');
var adapter = redis({ host : 'localhost', port : 6379});
io.adapter(adapter);
So the question is what exactly it does behind the scene? Do i need to install node_redis to store the chat messages?
Upvotes: 1
Views: 1579
Reputation: 305
If you want to store the messages on for example in a chat application, of course, Redis is not a good idea. It runs on memory. You need to use a DB solution works on disk. You can use still Redis in your socket io application but not for storing data purpose. Generally, people use Redis on socket.io apps as a backplane. So, for example, you developed a socket.io application, and you want to make it more than one instance, you need to share the data because you are gonna push one message to one instance, also other instances should inform about it. In that point Redis pub, sub structure is going to help you.
Upvotes: 0
Reputation: 17846
I believe you have misunderstood this project. To quote their page:
By running socket.io with the socket.io-redis adapter you can run multiple socket.io instances in different processes or servers that can all broadcast and emit events to and from each other.
Which means that using this module will provide a socket.io cluster, giving the ability to send messages between clients running on different processes or servers
Upvotes: 3