I am trying to build a multi dimensional array with node.js using redis as the data source. I am however not doing it right.
the menuKey contains key containing a sorted set in redis, the sorted set contains values referencing other keys. e.g:
menu:main:sections contains ["menu:main:section1","menu:main:section2"]
menu:main:section1 contains ["option1", "option2"]
menu:main:section2 contains ["option1"]
the array I am trying to build:
[["option1", "option2"], ["option1"]]
This is the code I have but I am placing a callback wrong somehow?
function handleMenu(jsonrpc) {
var params = jsonrpc['params'];
var result = [];
var sections = [];
menuKey = 'menu:' + params['menu'] + ':sections';
async.series([
function (callback) {
redis.zrevrange(menuKey, 0, -1, function(err, sections) {
async.forEachSeries(sections, function(section, sectionCallback) {
redis.zrevrange(section, 0, -1, function(err, items) {
result.push(items);
sectionCallback();
});
}, callback);
});
}
], function() {
console.log(result);
});
}
I don't see what I am doing wrong, please advice.
["menu:main:section1": ["option1", "option2"]??{ "prop1" : [ index0, index1 ], "prop2" : [ index0 ] }(quotes around property names are optional in this format)array = [ [ index0, index1 ], [ index ] ]. If you want to map"menu:main:section1" -> 0somehow, and"menu:main:section2" -> 1go for it. But if you want to sayarray["menu:main:section1"][0] = "a";then you're using an object on the outside, and an array as the value of the property. Objects also support int-based prop names, but will suffer a small string-cast (0 -> "0") penalty in most engines, including V8.