Populating Redis

The ./lib/cache/populate.js script populates a Redis store with new commits/issues using our preceding modules. We will demonstrate scheduling this script later in the chapter. We start by importing the Publisher module, and use util.inherits to extend the Publisher module with a Populate function, giving our Populate module the ability to publish messages.

We then define the Populate function and add a run function, that gets all projects from MongoDB. We use async.each to loop through each project, using the projects user and token to instantiate a GitHubRepo module. We then call git.commits, passing a list of repositories; the response returned is a sorted list of the 10 latest commits. We save the response to Redis using

Get Advanced Express Web Application Development 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.