Reputation: 834
I am developing a little project using Node.js. I am using mongoose
for models, therefore i am using MongoDb
. And i keep sessions in MongoStore
. Also i want to use socket.io
running several processes of Node. From socket.io
docs:
The MemoryStore only allows you deploy socket.io on a single process.
If you want to scale to multiple process and / or multiple servers
you can use our RedisStore which uses the Redis
NoSQL database as man in the middle.
So i think i need Redis
too. I am new in Node and i want to know - is it normal to use two databases to manage different parts of application. Or is there a way to work with socket.io
when running several processes of Node and use only MongoDb
Upvotes: 0
Views: 1777
Reputation: 26939
Just recently a solution that uses MongoStore with pub/sub functionality using mubsub (Pub/sub for Node.js and MongoDB) has appeared.
It can be attached to socket.io in almost the same way as you would with RedisStore:
io.configure(function() {
io.set('store', new MongoStore({host: 'localhost', port: 27017, db:'session_db'}));
});
More information and source at: https://github.com/kof/socket.io-mongo
Upvotes: 4
Reputation: 63653
The Redis store is already built into Socket.IO, but more importantly has 2 important features that are particularly needed for Socket.IO:
1) Publish-subscribe (to communicate between processes)
2) Key-value store (to store all the info about connections)
While the key-value store part can be done with MongoDB, it doesn't provide the pub-sub functionality.
Bottom line, IF you need to scale beyond one process (meaning you are expecting more than some thousand concurrent request) than RedisStore is the solution.
Resources:
Upvotes: 2