I want to use the zunionstore command on sets which i define at runtime, they are fetched dynamically so i never know what the sets are that i have to pass to the function.
syntax of zunionstore:
ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
the parsed array contains the names of the sets.
client.zunionstore
(
'out',
parsed.length,
parsed,
function (err, res)
{
console.log(err);
if(!err)
{
client.zrevrange('out', 0, -1, 'withscores', function (err, res)
{
console.log(res);
if(!err)
{
//do stuff
}
});
}
}
);
as you can see i tried to pass the array containing the names but this doesn't work..
the error i get:
[Error: ERR syntax error]
Any ideas on how to solve this?
do you mean that you are having problems passing an array to a function? put all arguments into an array and call apply on the function: Passing an array as a function parameter in JavaScript
so, you have your parsed array, just add to it the other things like your 'out', parsed.length, etc, and call client.zunionstore.apply(this, array).