I'm really struggling with this async issue. I can't seem to get it to work because the summonerData array is not being set. I have a feeling it has something to do with async, but I'm not sure how to troubleshoot it.
var summonerName = req.params.playerName;
var summonerData = [];
var summonerIds = [];
var summonerGames = [];
redis.exists(summonerName, function(err, reply) {
if (reply === 1) {
console.log('Data Found for Summoner in Redis!: ' + summonerName);
redis.hgetall(summonerName, function(err, object) {
summonerData.push(object);
});
} else {
console.log('Data not Found for Summoner: ' + summonerName);
lolapi.Summoner.getByName(summonerName, function(error, summoner) {
if (summoner) {
console.log('Summoner was retrieved by API! and Saved to Redis!');
redis.hmset(summonerName, summoner[summonerName]);
summonerData.push(summoner[summonerName]);
}
});
}
});
console.log(summonerData);