Using Redis to pass events between nodes
Now that we are able to run multiple nodes simultaneously with Socket.IO and not loose our socket connection between events, we will also need a way to ensure that, when an event is emitted on one node, it is also emitted across all of our other nodes.
For this, Socket.IO uses an interface called an adapter to route messages, and it allows us to use something other than the default memory-based adapter, so we can use our own instead. For a distributed system, we will need to use an adapter that lives outside of our server nodes.
Redis is a perfect solution for this problem. Redis is a key-value store, and cache is stored outside the web servers. This means that we can spin the instances of the server up and ...
Get Socket.IO Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.