Been struggling with this for the past hour, can't seem to figure it out:
app.get('/bk/domains/get', function (req, res) {
client.keys('*', function (e, d) {
d.forEach(function (data) {
client.hgetall(data, function (e, d) {
res.json({'host': data, 'config': d});
});
});
});
});
Here is example output:
{
"host": "test.com",
"config": {
"url": "http://test.com/test.html",
"token": "source",
"account": "test",
"source": "google"
}
}
Right now, because of res.json it dies right after spitting out the first value from client.hgetall. There are about 10 other values that I would like to add to this json response, but can't seem to get it working. How do I go about doing this?
I tried this:
app.get('/bk/domains/get', function (req, res) {
var arr = [];
client.keys('*', function (e, d) {
d.forEach(function (data) {
client.hgetall(data, function (e, d) {
arr.push({'host': data, 'config': d});
});
});
});
});
But arr
is always empty. I also tried to move arr
outside of app.get as it may have been the namespace, but that doesn't work either.
How can I push the 10 values from hgetall into a single array and return it as json?
Thank you in advance!