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 project._id
as the key. We then publish the project._id
and commits
, via the publish
function to activate a refresh. We then repeat the whole process for issues
.
var async = require('async') , _ = require('underscore') , util = require('util') ...