From e11efad0b71f8d8337a0318feb32a71c6fa2b90a Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 18 Mar 2014 13:25:05 -0400 Subject: [PATCH] added getSortedSetRangeByScore --- src/database/mongo.js | 13 ++++++++++--- src/database/redis.js | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 7b6705fbfd..aaf161ee42 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -538,7 +538,15 @@ getSortedSetRange(key, start, stop, -1, callback); }; + module.getSortedSetRangeByScore = function(args, callback) { + getSortedSetRangeByScore(args, 1, callback); + }; + module.getSortedSetRevRangeByScore = function(args, callback) { + getSortedSetRangeByScore(args, -1, callback); + }; + + function getSortedSetRangeByScore(args, sort, callback) { var key = args[0], max = (args[1] === '+inf') ? Number.MAX_VALUE : args[1], min = args[2], @@ -552,20 +560,19 @@ db.collection('objects').find({_key:key, score: {$gte:min, $lte:max}}, {fields:{value:1}}) .limit(count) .skip(start) - .sort({score: -1}) + .sort({score: sort}) .toArray(function(err, data) { if(err) { return callback(err); } - // maybe this can be done with mongo? data = data.map(function(item) { return item.value; }); callback(err, data); }); - }; + } module.sortedSetCount = function(key, min, max, callback) { db.collection('objects').count({_key:key, score: {$gte:min, $lte:max}}, function(err, count) { diff --git a/src/database/redis.js b/src/database/redis.js index 58a5da9ee7..90daed3e74 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -359,6 +359,10 @@ redisClient.zrevrange(key, start, stop, callback); }; + module.getSortedSetRangeByScore = function(args, callback) { + redisClient.zrangebyscore(args, callback); + }; + module.getSortedSetRevRangeByScore = function(args, callback) { redisClient.zrevrangebyscore(args, callback); };