sortedSetCount fix for +inf/-inf

v1.18.x
barisusakli 10 years ago
parent 03ee524121
commit 0a534b20e3

@ -204,7 +204,14 @@ module.exports = function(db, module) {
if (!key) {
return callback();
}
db.collection('objects').count({_key: key, score: {$gte: min, $lte: max}}, function(err, count) {
var scoreQuery = {};
if (min !== '-inf') {
scoreQuery.$gte = min;
}
if (max !== '+inf') {
scoreQuery.$lte = max;
}
db.collection('objects').count({_key: key, score: scoreQuery}, function(err, count) {
callback(err, count ? count : 0);
});
};

@ -141,7 +141,7 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRevRangeByScoreWithScores()', function() {
it('should get count elements with score between max min sorted by score highest to lowest', function(done) {
db.getSortedSetRevRangeByScoreWithScores('sorted2', 0, -1, '+inf', 1, function(err, values) {
db.getSortedSetRevRangeByScoreWithScores('sorted2', 0, -1, '+inf', 2, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}]);

Loading…
Cancel
Save