我正在设置一个 for 循环来向 Redis 添加数据。由于所有 Redis 调用都是异步的,而且我不能只添加 JSON 对象,因此我正在尝试使用for..of
循环来添加所有内容。我的问题是由于某种原因它没有运行循环。这是代码:
var idObj = {"id": profileId}
if(){
// this code is working fine
} else {
console.log('made it to the else statement');
async function AsyncForLoop() {
for (var key of Object.keys(idObj)) {
console.log('in the for loop');
await hsetAsync(profileId, key, idObj[key]);
}
AsyncForLoop();
json.status = "ok";
res.send(JSON.stringify(json));
};
}
我可以访问“使其成为 else 语句”控制台日志,但它实际上从未运行过 for 循环。我尝试将其设为异步函数,然后调用该函数,但它仍然没有运行。我什至没有得到res.send()
我在这里缺少什么的回应?