Adding a new worker

We have one small problem at this point. As time goes on, more and more rooms will be created and more messages will accumulate. Eventually, we will run Redis out of memory. We are not being good Redis citizens. We need to remove our Redis data and will do this with a new worker.

Create a file named chat.js under the workers directory. Start the function with the following code:

var client = require('../redis').client,
  log = require('../middleware/log');

var delta = 60 * 60 * 1000 * 3; //10800000
var interval = 60 * 60 * 1000 * 2; //7200000

We include our Redis client and logger. Then, we set up our delta and interval. We will remove any room, chat, or user that has been inactive or was created 3 hours ago (10,800,000 milliseconds ...

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.