Does socket.io-redis support redis clusters? - node.js

Can I use a redis cluster transparently (without writing any client side code for the redis cluster) with socket-io-redis instead of a single redis server as the default examples state? Unfortunately, there seems to be no official documentation on this.
Also, without a redis cluster, how many users can socket.io servers support with a single redis server as socket.io-redis backend?
Update:
Socket.io-redis allows specification of redis clients to use. May be some node_redis compatible redis client which also has support for redis clusters can be used? ioredis (the only other full featured/recommended client) has support for redis clusters but I am not sure if it's compatible with the node_redis client. Does anyone have some info on it or other possible solutions?
Note: I know Redis cloud provides scaling solution with a single endpoint paradigm but I need a cluster solution.

The module socket.io-ioredis allows use of ioredis with socket.io. Ioredis can connect to a redis cluster. However, I have, so far, only used socket.io-ioredis with socket.io with a single node server and single redis instance and it's working okay in this configuration.

Related

How to share cache between nodejs clusters?

I have been using the nestjs CacheModule along with cache-manager-redis-store as a cache store in an API. Recently I started clustering the app using node's cluster module. But now it seems like each cluster has it's own separate cache. Is it possible for the cache to be shared between all clusters? If not, what are other options for caching alongside clustering?
The workaround I used was ditching the nestjs CacheModule and connecting to the redis server directly using a redis client (node-redis).
I think the nestjs CacheModule is tied to the node process which makes each cluster have a different cache. But since the redis server exists outside node, it does not have the same constraints.

How to implement PM2 clustering with WebSockets, Nodejs

I am writing real time connection web server with WebSocket(ws) library in Node js(Express).so when I am running server on pm2 cluster mode than websocket not working properly.Is there any way to make share data between pm2 clusters with websocket.
From what I understand, that's kind of the point of cluster mode. It wouldn't be able to keep the connection alive across multiple "nodes" running processes. Straight from the PM2 docs:
Be sure your application is stateless meaning that no local data is stored in the process, for example sessions/websocket connections, session-memory and related. Use Redis, Mongo or other databases to share states between processes.
If you could pull out your websocket into its own instance and avoid side effects from a pm2 cluster--that's probably the most performant, although maybe not feasible in your set up. Best of luck!
You can switch the library to socket.io they already solve this issue by using redis adapter for socket.io Socket.IO Redis
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.

Redis pub/sub scalling, Socket.io on Node Js

I have developed multiplayer turn-based application on Node Js using socket.io and redis pub/sub.
Brief regarding my implementation are as follows:
Multiplayer turn-based game scaled over ALB using socket.io-redis adapter for redis pub-sub.
My concurrent user base is around ~0.4 Million so I need to scale redis pub-sub as that is a single node as well.
I went through below Links:
https://www.youtube.com/watch?v=6G22a5Iooqk
https://groups.google.com/forum/#!topic/redis-db/B0_fvfDWLGM
Can anyone elaborate how should I proceed for this.

in node.js, socket.io using redis - is this redis available for nomal redis use?

my understanding is that socket.io uses redis
socket.set( 'var', val1 );
var val2 = socket.get( 'var' );
but redis is not in node_modules
does socket.io use its own private instance of redis? if not, is is possible, through a redis client, to access socket.io values stored in redis?
Redis is used by Socket.io to store information about sockets. You need to use it if you have several socket.io servers for the same application.
Obviously you can use this redis for your application if you don't override the data of socket.io.
Socket.io uses the publish/subscribe functionality of redis (see documentation), not the key/value store.

node js using Mongo and Redis simulteniously

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
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
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:
Examples in using RedisStore in socket.io
http://www.ranu.com.ar/2011/11/redisstore-and-rooms-with-socketio.html

Resources