O'Reilly logo

Building Scalable Apps with Redis and Node.js by Joshua Johanan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required