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 down. As a result, the data that is stored in Redis will not be lost. By plugging Redis into our Socket.IO adapter, we can propagate events across our nodes rather painlessly.
Getting ready
First, we will need to have an instance of Redis running....