Skip to content

Instantly share code, notes, and snippets.

@JetFault
Created June 22, 2012 20:47
Show Gist options
  • Save JetFault/2975084 to your computer and use it in GitHub Desktop.
Save JetFault/2975084 to your computer and use it in GitHub Desktop.
Redis Pop in Series
/**
* Query Redis for emails still needing to be parsed
* Should return error if no items exist
* @param user_name
* @param cb - Callback(err,
* [ {uid: }, {msgid: } ],...
* Note: Will return NO_EMAILS_TO_PARSE error when
* no emails to parse
*/
var getUIDAttachList = function(user_name, cb) {
var attachList = [];
//Pops in Series
var popAll = function(done_cb) {
redisClient.lpop(user_name, function(err, msg_id) {
if(err) {
logger.error("Error popping msg_id from " + user_name + ": "+ err);
} else {
if(!msg_id) {
done_cb();
} else {
redisClient.hgetall(msg_id, function(err, email) {
if(err) {
logger.error("Error getting hash for " + msg_id + ": " + err);
} else {
attachList.push(email);
}
popAll(done_cb);
});
}
}
});
};
popAll(function() {
if(attachList.length === 0) {
cb(NO_EMAILS_TO_PARSE);
} else {
cb(null, attachList);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment