From e8e33a8a23cdbc1d44d975a549fb3d2aa3277a53 Mon Sep 17 00:00:00 2001 From: Moritz Schmidt Date: Sun, 4 Dec 2016 17:41:27 +0100 Subject: [PATCH] ZSET scores are float: parseInt => parseFloat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Redis, scores of sorted sets can be floats – so we should use `parseFloat` instead of `parseInt` when converting from string to number. Should not lead to #4939 again, as `new Date()` works regardless of whether it's being passed a float or integer. --- src/database/redis/sorted.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js index 2230f0498a..9e50c158c7 100644 --- a/src/database/redis/sorted.js +++ b/src/database/redis/sorted.js @@ -115,7 +115,7 @@ module.exports = function (redisClient, module) { } var objects = []; for(var i = 0; i < data.length; i += 2) { - objects.push({value: data[i], score: parseInt(data[i + 1], 10)}); + objects.push({value: data[i], score: parseFloat(data[i + 1])}); } callback(null, objects); }); @@ -144,7 +144,7 @@ module.exports = function (redisClient, module) { } var objects = []; for(var i = 0; i < data.length; i += 2) { - objects.push({value: data[i], score: parseInt(data[i + 1], 10)}); + objects.push({value: data[i], score: parseFloat(data[i + 1])}); } callback(null, objects); }); @@ -195,7 +195,7 @@ module.exports = function (redisClient, module) { module.sortedSetScore = function (key, value, callback) { redisClient.zscore(key, value, function (err, score) { - callback(err, !err ? parseInt(score, 10) : undefined); + callback(err, !err ? parseFloat(score) : undefined); }); }; @@ -289,7 +289,7 @@ module.exports = function (redisClient, module) { results = results[1] || []; var objects = []; for(var i = 0; i < results.length; i += 2) { - objects.push({value: results[i], score: parseInt(results[i + 1], 10)}); + objects.push({value: results[i], score: parseFloat(results[i + 1])}); } callback(null, objects); }); @@ -297,7 +297,7 @@ module.exports = function (redisClient, module) { module.sortedSetIncrBy = function (key, increment, value, callback) { redisClient.zincrby(key, increment, value, function (err, newValue) { - callback(err, !err ? parseInt(newValue, 10) : undefined); + callback(err, !err ? parseFloat(newValue) : undefined); }); }; @@ -419,4 +419,4 @@ module.exports = function (redisClient, module) { callback(null, objects); }); } -}; \ No newline at end of file +};