I'm trying to executes two functions async series with node.JS. But I don't understand to do this.
Now, I have:
function 1:
function search(client_id, callback) {
clientRedis.keys('director:*', function (err, results) {
results.forEach(function (key) {
clientRedis.hgetall(key, function (err, obj) {
//SAVE RESULT
console.log('save');
});
});
});
callback(null, results);
}
function 2:
function range(client_id, callback) {
//Sort my array
callback(null, results);
}
And I call this functions here:
async.series([
search(client_id),
range(client_id);
], function (err, result) {
console.log(err);
console.log(result);
});
My problem: Second function is execute before the first because the first take more time. I need the result to first function to range my array with the function 2.
redis.keysisn't recommended in production because it scans all the keys?