added getSortedSetRangeByScore

v1.18.x
barisusakli 11 years ago
parent 2badb76fc2
commit e11efad0b7

@ -538,7 +538,15 @@
getSortedSetRange(key, start, stop, -1, callback); getSortedSetRange(key, start, stop, -1, callback);
}; };
module.getSortedSetRangeByScore = function(args, callback) {
getSortedSetRangeByScore(args, 1, callback);
};
module.getSortedSetRevRangeByScore = function(args, callback) { module.getSortedSetRevRangeByScore = function(args, callback) {
getSortedSetRangeByScore(args, -1, callback);
};
function getSortedSetRangeByScore(args, sort, callback) {
var key = args[0], var key = args[0],
max = (args[1] === '+inf') ? Number.MAX_VALUE : args[1], max = (args[1] === '+inf') ? Number.MAX_VALUE : args[1],
min = args[2], min = args[2],
@ -552,20 +560,19 @@
db.collection('objects').find({_key:key, score: {$gte:min, $lte:max}}, {fields:{value:1}}) db.collection('objects').find({_key:key, score: {$gte:min, $lte:max}}, {fields:{value:1}})
.limit(count) .limit(count)
.skip(start) .skip(start)
.sort({score: -1}) .sort({score: sort})
.toArray(function(err, data) { .toArray(function(err, data) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
// maybe this can be done with mongo?
data = data.map(function(item) { data = data.map(function(item) {
return item.value; return item.value;
}); });
callback(err, data); callback(err, data);
}); });
}; }
module.sortedSetCount = function(key, min, max, callback) { module.sortedSetCount = function(key, min, max, callback) {
db.collection('objects').count({_key:key, score: {$gte:min, $lte:max}}, function(err, count) { db.collection('objects').count({_key:key, score: {$gte:min, $lte:max}}, function(err, count) {

@ -359,6 +359,10 @@
redisClient.zrevrange(key, start, stop, callback); redisClient.zrevrange(key, start, stop, callback);
}; };
module.getSortedSetRangeByScore = function(args, callback) {
redisClient.zrangebyscore(args, callback);
};
module.getSortedSetRevRangeByScore = function(args, callback) { module.getSortedSetRevRangeByScore = function(args, callback) {
redisClient.zrevrangebyscore(args, callback); redisClient.zrevrangebyscore(args, callback);
}; };

Loading…
Cancel
Save