diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js index a3b1700545..24b595f565 100644 --- a/src/database/redis/sorted.js +++ b/src/database/redis/sorted.js @@ -167,11 +167,27 @@ module.exports = function (redisClient, module) { }; module.sortedSetsScore = function (keys, value, callback) { - helpers.execKeysValue(redisClient, 'batch', 'zscore', keys, value, callback); + helpers.execKeysValue(redisClient, 'batch', 'zscore', keys, value, function (err, scores) { + if (err) { + return callback(err); + } + scores = scores.map(function (d) { + return d === null ? d : parseFloat(d); + }); + callback(null, scores); + }); }; module.sortedSetScores = function (key, values, callback) { - helpers.execKeyValues(redisClient, 'batch', 'zscore', key, values, callback); + helpers.execKeyValues(redisClient, 'batch', 'zscore', key, values, function (err, scores) { + if (err) { + return callback(err); + } + scores = scores.map(function (d) { + return d === null ? d : parseFloat(d); + }); + callback(null, scores); + }); }; module.isSortedSetMember = function (key, value, callback) { diff --git a/test/database/sorted.js b/test/database/sorted.js index 13975b0b53..cc7454a92c 100644 --- a/test/database/sorted.js +++ b/test/database/sorted.js @@ -465,7 +465,7 @@ describe('Sorted Set methods', function () { db.sortedSetScore('sortedSetTest1', 'value2', function (err, score) { assert.equal(err, null); assert.equal(arguments.length, 2); - assert.equal(score, 1.2); + assert.strictEqual(score, 1.2); done(); }); }); @@ -515,28 +515,37 @@ describe('Sorted Set methods', function () { it('should return 0 if score is 0', function (done) { db.sortedSetScores('zeroScore', ['value1'], function (err, scores) { assert.ifError(err); - assert.equal(0, scores[0]); + assert.strictEqual(0, scores[0]); done(); }); }); it('should return the scores of value in sorted sets', function (done) { db.sortedSetScores('sortedSetTest1', ['value2', 'value1', 'doesnotexist'], function (err, scores) { - assert.equal(err, null); + assert.ifError(err); assert.equal(arguments.length, 2); - assert.deepEqual(scores, [1.2, 1.1, null]); + assert.deepStrictEqual(scores, [1.2, 1.1, null]); 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.ifError(err); assert.equal(arguments.length, 2); - assert.deepEqual(scores, [1.2, null, null]); + assert.deepStrictEqual(scores, [1.2, null, null]); done(); }); }); + + it('should return scores properly', function (done) { + db.sortedSetsScore(['zeroScore', 'sortedSetTest1', 'doesnotexist'], 'value1', function (err, scores) { + assert.ifError(err); + assert.equal(arguments.length, 2); + assert.deepStrictEqual(scores, [0, 1.1, null]); + done(); + }); + }) }); describe('isSortedSetMember()', function () { @@ -775,7 +784,7 @@ describe('Sorted Set methods', function () { assert.equal(arguments.length, 1); db.sortedSetsScore(['sorted4', 'sorted5'], 'value1', function (err, scores) { assert.equal(err, null); - assert.deepEqual(scores, [null, null]); + assert.deepStrictEqual(scores, [null, null]); done(); }); });