I use node_redis module for caching comments and need get this comments when new will approved.
Function that get comments from Redis store below:
var client = redis.createClient();
........
function getComments() {
client.keys("*", function (err, replies) {
var comments = [];
if (err) throw new Error('Redis error');
//console.log(replies.length + " replies:");
replies.forEach(function (reply, i) {
client.get(reply, function (err, value) {
if (err) throw new Error('Redis error');
//console.log(i+" " + reply + ": " + value);
comments[i] = value;
console.log(comments); //comments - not empty here
});
});
console.log(comments); //comments is empty here
client.quit();
});
}
Problem desribed in comments. When forEach finished it works, comments array is empty. How can I add callback for foreach to save scope with comments to get then data from this array ?