fixed tests, and added getSortedSetUnion method to redis db, added test for new redis method

This commit is contained in:
Julian Lam
2014-05-23 08:57:51 -04:00
parent 840a56006c
commit 6e597a9cdb
6 changed files with 73 additions and 23 deletions

View File

@@ -73,4 +73,33 @@ module.exports = function(redisClient, module) {
multi.exec(callback);
};
module.getSortedSetUnion = function(sets, start, stop, callback) {
// start and stop optional
if (typeof start === 'function') {
callback = start;
start = 0;
stop = -1;
} else if (typeof stop === 'function') {
callback = stop;
stop = -1;
}
var multi = redisClient.multi();
// zunionstore prep
sets.unshift(sets.length);
sets.unshift('temp');
multi.zunionstore.apply(multi, sets);
multi.zrange('temp', start, stop);
multi.del('temp');
multi.exec(function(err, results) {
if (!err && typeof callback === 'function') {
callback(null, results[1]);
} else if (err) {
callback(err);
}
});
}
};