gpt4 book ai didi

javascript - Node.js 中是否可以嵌套 Redis 语句?

转载 作者:可可西里 更新时间:2023-11-01 11:22:02 26 4
gpt4 key购买 nike

我得到了以下包含嵌套 redis 语句的代码

   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

但是,永远不会到达最后一个控制台日志语句。这几乎就像是在一个无限循环中......

知道如何摆脱这个吗?

谢谢

最佳答案

您的最终控制台日志在 redis 调用之外。所以当NodeJS异步调用redis LRANGE 时会立即调用。将它放在 LRANGE 回调中。

关于javascript - Node.js 中是否可以嵌套 Redis 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22854398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com