no upgrade script yet
This commit is contained in:
barisusakli
2015-05-19 23:04:28 -04:00
parent 56e5f505a0
commit aa577f4adc
11 changed files with 202 additions and 151 deletions

View File

@@ -509,4 +509,28 @@ module.exports = function(db, module) {
callback(err, result && result.value ? result.value.score : null);
});
};
module.getSortedSetRangeByLex = function(key, min, max, start, count, callback) {
var query = {_key: key};
if (min !== '-') {
query.value = {$gte: min};
}
if (max !== '+') {
query.value = query.value || {};
query.value.$lte = max;
}
db.collection('objects').find(query, {_id: 0, value: 1})
.sort({value: 1})
.skip(start)
.limit(count === -1 ? 0 : count)
.toArray(function(err, data) {
if (err) {
return callback(err);
}
data = data.map(function(item) {
return item && item.value;
});
callback(err, data);
});
};
};

View File

@@ -246,4 +246,14 @@ module.exports = function(redisClient, module) {
module.sortedSetIncrBy = function(key, increment, value, callback) {
redisClient.zincrby(key, increment, value, callback);
};
module.getSortedSetRangeByLex = function(key, min, max, start, count, callback) {
if (min !== '-') {
min = '[' + min;
}
if (max !== '+') {
max = '(' + max;
}
redisClient.zrangebylex([key, min, max, 'LIMIT', start, count], callback);
};
};