I've got the following code that contains a nested redis statement
var objList =new Array();
//Hardcoded key
client.LRANGE("user4feed","0","-1",function(err,user){
user.forEach(function (reply, i) {
//console.log(" " + i + ": " + reply);
client.HGETALL('photo:'+reply,function(err,user){
var test = user; //Cant go array directly, will say 'user' is undefined
objList.push(test);
})
});
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?
Thanks
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.