From 5222edb6243a103f2efc0cfad695464299a767e6 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 8 Sep 2014 16:13:48 -0400 Subject: [PATCH] sortedSetsAdd using mullti/bulk for redis/mongo lets you add a score/value pair to multiple sorted sets at once --- src/database/level/sorted.js | 8 ++++++++ src/database/mongo/sorted.js | 21 +++++++++++++++++++++ src/database/redis/sorted.js | 13 +++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/database/level/sorted.js b/src/database/level/sorted.js index 369c820d53..ac681bb65b 100644 --- a/src/database/level/sorted.js +++ b/src/database/level/sorted.js @@ -20,6 +20,14 @@ module.exports = function(db, module) { }); }; + module.sortedSetsAdd = function(keys, score, value, callback) { + async.each(keys, function(key, next) { + module.sortedSetAdd(key, score, value, next); + }, function(err) { + callback(err); + }); + }; + module.sortedSetRemove = function(key, value, callback) { module.getListRange(key, 0, -1, function(err, set) { set = set.filter(function(a) {return a.value !== value.toString();}); diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js index c290b7000a..9e31335308 100644 --- a/src/database/mongo/sorted.js +++ b/src/database/mongo/sorted.js @@ -18,6 +18,26 @@ module.exports = function(db, module) { }); }; + module.sortedSetsAdd = function(keys, score, value, callback) { + callback = callback || helpers.noop; + + value = helpers.valueToString(value); + var data = { + score: parseInt(score, 10), + value: value + }; + + var bulk = db.collection('objects').initializeUnorderedBulkOp(); + + for(var i=0; i