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