diff --git a/.eslintrc b/.eslintrc index bbba3aa94e..4f7d4e2413 100644 --- a/.eslintrc +++ b/.eslintrc @@ -54,9 +54,9 @@ "no-restricted-syntax": "off", "no-script-url": "off", "default-case": "off", + "linebreak-style": "off", // "no-multi-assign": "off", - // "linebreak-style": "off", // "one-var": "off", // "no-undef": "off", // "max-nested-callbacks": "off", diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js index 59bd05b9fd..4168199bb5 100644 --- a/src/database/mongo/sorted.js +++ b/src/database/mongo/sorted.js @@ -241,7 +241,7 @@ module.exports = function (db, module) { module.sortedSetScore = function (key, value, callback) { if (!key) { - return callback(); + return callback(null, null); } value = helpers.valueToString(value); db.collection('objects').findOne({ _key: key, value: value }, { fields: { _id: 0, score: 1 } }, function (err, result) { @@ -274,7 +274,7 @@ module.exports = function (db, module) { module.sortedSetScores = function (key, values, callback) { if (!key) { - return callback(); + return callback(null, null); } values = values.map(helpers.valueToString); db.collection('objects').find({ _key: key, value: { $in: values } }, { _id: 0, value: 1, score: 1 }).toArray(function (err, result) { diff --git a/src/database/redis/helpers.js b/src/database/redis/helpers.js index 7100437177..b1c2a98092 100644 --- a/src/database/redis/helpers.js +++ b/src/database/redis/helpers.js @@ -1,6 +1,6 @@ 'use strict'; -var helpers = {}; +var helpers = module.exports; helpers.multiKeys = function (redisClient, command, keys, callback) { callback = callback || function () {}; @@ -15,7 +15,7 @@ helpers.multiKeysValue = function (redisClient, command, keys, value, callback) callback = callback || function () {}; var multi = redisClient.multi(); for (var i = 0; i < keys.length; i += 1) { - multi[command](keys[i], value); + multi[command](String(keys[i]), String(value)); } multi.exec(callback); }; @@ -24,7 +24,7 @@ helpers.multiKeyValues = function (redisClient, command, key, values, callback) callback = callback || function () {}; var multi = redisClient.multi(); for (var i = 0; i < values.length; i += 1) { - multi[command](key, values[i]); + multi[command](String(key), String(values[i])); } multi.exec(callback); }; @@ -35,5 +35,3 @@ helpers.resultsToBool = function (results) { } return results; }; - -module.exports = helpers; diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js index 67f55bf343..9bb004550a 100644 --- a/src/database/redis/sorted.js +++ b/src/database/redis/sorted.js @@ -124,8 +124,12 @@ module.exports = function (redisClient, module) { }; module.sortedSetScore = function (key, value, callback) { + if (!key || value === undefined) { + return callback(null, null); + } + redisClient.zscore(key, value, function (err, score) { - callback(err, !err ? parseFloat(score) : undefined); + callback(err, !err ? parseFloat(score) : null); }); }; diff --git a/test/database/sorted.js b/test/database/sorted.js index 939f4b259e..b90e9cf71f 100644 --- a/test/database/sorted.js +++ b/test/database/sorted.js @@ -324,6 +324,22 @@ describe('Sorted Set methods', function () { done(); }); }); + + it('should not error if key is undefined', function (done) { + db.sortedSetScore(undefined, 1, function (err, score) { + assert.ifError(err); + assert.strictEqual(score, null); + done(); + }); + }); + + it('should not error if value is undefined', function (done) { + db.sortedSetScore('sortedSetTest1', undefined, function (err, score) { + assert.ifError(err); + assert.strictEqual(score, null); + done(); + }); + }); }); describe('sortedSetsScore()', function () { @@ -335,6 +351,15 @@ describe('Sorted Set methods', function () { done(); }); }); + + it('should return scores even if some keys are undefined', function (done) { + db.sortedSetsScore(['sortedSetTest1', undefined, 'doesnotexist'], 'value1', function (err, scores) { + assert.equal(err, null); + assert.equal(arguments.length, 2); + assert.deepEqual(scores, [1.1, null, null]); + done(); + }); + }); }); describe('sortedSetScores()', function () { @@ -358,6 +383,15 @@ describe('Sorted Set methods', function () { done(); }); }); + + it('should return scores even if some values are undefined', function (done) { + db.sortedSetScores('sortedSetTest1', ['value2', undefined, 'doesnotexist'], function (err, scores) { + assert.equal(err, null); + assert.equal(arguments.length, 2); + assert.deepEqual(scores, [1.2, null, null]); + done(); + }); + }); }); describe('isSortedSetMember()', function () {