for loop over event driven code?

前端 未结 3 1327
孤街浪徒
孤街浪徒 2021-01-21 23:18

In a redis datastore I have a list of keys, I want to iterate over that list of keys and get those values from redis. The catch is I am using an event driven language, javascri

3条回答
  •  长情又很酷
    2021-01-22 00:02

    If you find yourself needing to use patterns like this often, then you may be interested in trying out the async.js library. Using async.js you could write something like this:

    function getAll(callback) {
        redis.lrange('mykey', 0, -1, function(err, reply) {
            async.concat(reply, redis.hgetall, callback);
        });
    };
    

    Which basically means "call hgetall on each item in 'reply' then concat all the results and pass to the callback".

提交回复
热议问题