Using Redis as the store for Socket.IO

The final thing we are going to add is to switch Socket.IO's internal communication about room participation. By default, Socket.IO will not let other Socket.IO nodes know about room changes. As we know now, we cannot have an application state that is stored only on one server. We need to store it in Redis. Therefore, we add it to index.js, present in packtchat\socket.io. Add the following code to the variable declarations:

Var redisAdapter = require('socket.io-redis');

Note

An application state is a flexible idea. We can store the application state locally. This is done when the state does not need to be shared. A simple example is keeping the path to a local temp file. When the data will be needed by multiple ...

Get Building Scalable Apps with Redis and Node.js 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.