node.js async mapSeries of smembers

2019-08-10 04:32发布

Having a list of keys I try to fetch all there values from redis, like following

 async.mapSeries(['offer','find'],function (seed) {
    client.smembers(string);
},
   function(err, resultArr) {
      err && console.trace(err);
      console.log(resultArr)
})

Of course it doesn't work, what I expect to see that resultArr contains the values of keys ['offer','find'].

1条回答
乱世女痞
2楼-- · 2019-08-10 04:56

You have forgotten to add any callbacks to delegate the data forward. Change the iterator function to something like this:

function (seed, cb) {
  client.smembers(string, cb);
}

This instructs Redis to tell async that it is done transforming the data, and what the result is. You current code never reaches the final callback since async never considers the loop to be done.

查看更多
登录 后发表回答