mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-07 18:00:16 +02:00
unread changes
This commit is contained in:
@@ -136,14 +136,18 @@ module.exports = function(db, module) {
|
||||
};
|
||||
|
||||
module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
|
||||
getSortedSetRangeByScore(key, start, count, min, max, 1, callback);
|
||||
getSortedSetRangeByScore(key, start, count, min, max, 1, false, callback);
|
||||
};
|
||||
|
||||
module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) {
|
||||
getSortedSetRangeByScore(key, start, count, min, max, -1, callback);
|
||||
getSortedSetRangeByScore(key, start, count, min, max, -1, false, callback);
|
||||
};
|
||||
|
||||
function getSortedSetRangeByScore(key, start, count, min, max, sort, callback) {
|
||||
module.getSortedSetRevRangeByScoreWithScores = function(key, start, count, max, min, callback) {
|
||||
getSortedSetRangeByScore(key, start, count, min, max, -1, true, callback);
|
||||
};
|
||||
|
||||
function getSortedSetRangeByScore(key, start, count, min, max, sort, withScores, callback) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
@@ -159,7 +163,13 @@ module.exports = function(db, module) {
|
||||
scoreQuery['$lte'] = max;
|
||||
}
|
||||
|
||||
db.collection('objects').find({_key:key, score: scoreQuery}, {fields:{value:1}})
|
||||
var fields = {_id: 0};
|
||||
fields['value'] = 1;
|
||||
if (withScores) {
|
||||
fields['score'] = 1;
|
||||
}
|
||||
|
||||
db.collection('objects').find({_key:key, score: scoreQuery}, {fields: fields})
|
||||
.limit(count)
|
||||
.skip(start)
|
||||
.sort({score: sort})
|
||||
@@ -168,9 +178,11 @@ module.exports = function(db, module) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
data = data.map(function(item) {
|
||||
return item.value;
|
||||
});
|
||||
if (!withScores) {
|
||||
data = data.map(function(item) {
|
||||
return item.value;
|
||||
});
|
||||
}
|
||||
|
||||
callback(err, data);
|
||||
});
|
||||
|
||||
@@ -98,6 +98,10 @@ module.exports = function(redisClient, module) {
|
||||
redisClient.zrevrangebyscore([key, max, min, 'LIMIT', start, count], callback);
|
||||
};
|
||||
|
||||
module.getSortedSetRevRangeByScoreWithScores = function(key, start, count, max, min, callback) {
|
||||
redisClient.zrevrangebyscore([key, max, min, 'WITHSCORES', 'LIMIT', start, count], callback);
|
||||
};
|
||||
|
||||
module.sortedSetCount = function(key, min, max, callback) {
|
||||
redisClient.zcount(key, min, max, callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user