From be3b35dea34cf39b533e5c8338509838ea518675 Mon Sep 17 00:00:00 2001 From: yariplus Date: Sun, 16 Oct 2016 21:53:02 -0400 Subject: [PATCH] fix callbacks and regex --- src/database/mongo/sorted.js | 32 ++++++++++++++++++++------------ src/database/redis/sorted.js | 21 ++++++++++----------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js index d9183521c6..8fc21cb50a 100644 --- a/src/database/mongo/sorted.js +++ b/src/database/mongo/sorted.js @@ -596,18 +596,22 @@ module.exports = function (db, module) { var query = {_key: key, value: {}}; if (min !== '-') { - if (min.match('(')) { - query.value = {$gt: parseInt(min, 10)}; + if (min.match(/^\(/)) { + query.value = {$gt: min.slice(1)}; + } else if (min.match(/^\[/)) { + query.value = {$gte: min.slice(1)}; } else { - query.value = {$gte: parseInt(min, 10)}; + query.value = {$gte: min}; } } if (max !== '+') { query.value = query.value || {}; - if (max.match('(')) { - query.value = {$lt: parseInt(max, 10)}; + if (max.match(/^\(/)) { + query.value.$lt = max.slice(1); + } else if (max.match(/^\[/)) { + query.value.$lte = max.slice(1); } else { - query.value = {$lte: parseInt(max, 10)}; + query.value.$lte = max; } } @@ -632,18 +636,22 @@ module.exports = function (db, module) { var query = {_key: key}; if (min !== '-') { - if (min.match('(')) { - query.value = {$gt: parseInt(min, 10)}; + if (min.match(/^\(/)) { + query.value = {$gt: min.slice(1)}; + } else if (min.match(/^\[/)) { + query.value = {$gte: min.slice(1)}; } else { - query.value = {$gte: parseInt(min, 10)}; + query.value = {$gte: min}; } } if (max !== '+') { query.value = query.value || {}; - if (max.match('(')) { - query.value = {$lt: parseInt(max, 10)}; + if (max.match(/^\(/)) { + query.value.$lt = max.slice(1); + } else if (max.match(/^\[/)) { + query.value.$lte = max.slice(1); } else { - query.value = {$lte: parseInt(max, 10)}; + query.value.$lte = max; } } diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js index f8be7b3754..0077ab13ec 100644 --- a/src/database/redis/sorted.js +++ b/src/database/redis/sorted.js @@ -293,23 +293,24 @@ module.exports = function (redisClient, module) { }; module.getSortedSetRangeByLex = function (key, min, max, start, count, callback) { - sortedSetLex('zrangebylex', false, key, min, max, start, count, callback) + sortedSetLex('zrangebylex', false, key, min, max, start, count, callback); }; module.getSortedSetRevRangeByLex = function (key, max, min, start, count, callback) { - sortedSetLex('zrevrangebylex', true, key, max, min, start, count, callback) + sortedSetLex('zrevrangebylex', true, key, max, min, start, count, callback); }; - module.sortedSetRemoveRangeByLex = function (key, min, max) { - sortedSetLex('zremrangebylex', false, key, min, max, callback) + module.sortedSetRemoveRangeByLex = function (key, min, max, callback) { + callback = callback || helpers.noop; + sortedSetLex('zremrangebylex', false, key, min, max, callback); }; - module.sortedSetLexCount = function (key, min, max) { - sortedSetLex('zlexcount', false, key, min, max, callback) + module.sortedSetLexCount = function (key, min, max, callback) { + sortedSetLex('zlexcount', false, key, min, max, callback); }; function sortedSetLex(method, reverse, key, min, max, start, count, callback) { - if (!callback) callback === start; + callback = callback || start; var minmin, maxmax; if (reverse) { @@ -321,12 +322,10 @@ module.exports = function (redisClient, module) { } if (min !== minmin) { - min = '' + min; - if (!min.match(/[\[\(]/)) min = '[' + min; + if (!min.match(/^[\[\(]/)) min = '[' + min; } if (max !== maxmax) { - max = '' + max; - if (!max.match(/[\[\(]/)) max = '[' + max; + if (!max.match(/^[\[\(]/)) max = '[' + max; } if (count) {