diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js index e1fcb0cc8e..8cf807d3a4 100644 --- a/src/database/redis/sorted.js +++ b/src/database/redis/sorted.js @@ -293,29 +293,45 @@ module.exports = function (redisClient, module) { }; module.getSortedSetRangeByLex = function (key, min, max, start, count, callback) { - if (min !== '-') { - min = '[' + min; - } - if (max !== '+') { - max = '(' + max; - } - - sortedSetRangeByLex('zrangebylex', key, min, max, start, count, callback) + sortedSetLex('zrangebylex', false, key, min, max, start, count, callback) }; module.getSortedSetRevRangeByLex = function (key, max, min, start, count, callback) { - if (min !== '-') { - min = '[' + min; - } - if (max !== '+') { - max = '(' + max; - } + sortedSetLex('zrevrangebylex', true, key, max, min, start, count, callback) + }; + + module.sortedSetRemoveRangeByLex = function (key, min, max) { + sortedSetLex('zremrangebylex', false, key, min, max, callback) + }; - sortedSetRangeByLex('zrevrangebylex', key, max, min, start, count, callback) + module.sortedSetLexCount = function (key, min, max) { + sortedSetLex('zlexcount', false, key, min, max, callback) }; - function sortedSetRangeByLex(method, key, min, max, start, count, callback) { - redisClient[method]([key, min, max, 'LIMIT', start, count], callback); + function sortedSetLex(method, reverse, key, min, max, start, count, callback) { + if (!callback) callback === start; + + if (reverse) { + if (min !== '+') { + min = '(' + min; + } + if (max !== '-') { + max = '[' + max; + } + } else { + if (min !== '-') { + min = '[' + min; + } + if (max !== '+') { + max = '(' + max; + } + } + + if (count) { + redisClient[method]([key, min, max, 'LIMIT', start, count], callback); + } else { + redisClient[method]([key, min, max], callback); + } } module.sortedSetIntersectCard = function (keys, callback) {