p0ny p0ny - 1 month ago 12
Node.js Question

Are Nested Redis statments possible in Node.js?

I've got the following code that contains a nested redis statement

var objList =new Array();

//Hardcoded key
user.forEach(function (reply, i) {
//console.log(" " + i + ": " + reply);
var test = user; //Cant go array directly, will say 'user' is undefined
console.log("List length = "+user.length);

console.log("objList= "+objList); //This is never reached

However, the last console log statement is never reached. It's almost as if it's in an infinite loop...

Any idea how to get out of this?


Answer Source

Your final console log is outside the redis call. So it is called immediately when NodeJS calls the redis LRANGE asynchronously. Put it inside the LRANGE callback.