为什么在使用 node 和 redis 时我的承诺没有解决?我的数组 returns 第一次迭代而不是等待整个代码 运行

Why aren't my promises resolving while using node and redis? My array returns the first iteration instead of waiting for the entire code to run

app.get('/lists/get_emails', function(req, res) {
  //  Return *all* the emails that appear in *any* of the lists in
  // `req.body.lists`. Emails should only appear once.
  let queryArr = req.query.lists.split(",");
  var retArr = [];
  Promise.all(queryArr.map(list => {
    redisClient.smembersAsync(list)
      .then((results) => {
        if(results) {
          console.log('retArr  before push', retArr);
          for (email in results) {
            retArr.push(results[email])
          }
          console.log('retArr after push', retArr);
          return Promise.all(retArr);
        } else {
          res.send({results: null});
        }
      })
      .then(result => {
        console.log('resssssss!', result);
        return Promise.all(result);
      })
      .catch(error => {
        console.log('error submitting final emails', error);
      });
  }))
})

返回 retArr 时,它包含一个列表的电子邮件,但不是全部。我的控制台日志显示列表已加载到 retArr 中,但似乎 retArr 在所有电子邮件被推送之前就返回了。为什么?

您的 redisClient.. 链 returns 一个承诺,但您没有将该承诺返回到地图。

return redisClient(... 应该修复它。