I'm trying to return a json object so that I can pass it back before a page is rendered to populate a list. My problem is that I can't figure out how to pass the object data out from the hgetall callback function. Here is my example with comments on what I'm missing:
var redis = require("redis"),
client = redis.createClient();
function createMobs() {
var mobObject = {
name: "Globlin",
hp: 12,
level: 1
};
client.hmset("monsterlist", "mobs", JSON.stringify(mobObject));
var myMobs = function(object) {
return object;
};
var getMobs = function(callback) {
client.hgetall("monsterlist", function(err, object) {
callback(object);
});
};
// This is returning undefined instead of my mob
console.log("mobs: ", getMobs(myMobs));
// Goal is to return moblist
// return getMobs(myMobs);
}
exports.createMobs = createMobs;