-
-
Save barisusakli/b00a5ba90e561ed6e8b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nconf = require('nconf'); | |
var async = require('async'); | |
nconf.file({ | |
file: 'config.json' | |
}); | |
var redis = require('redis'); | |
var db = require('./src/database'); | |
var batch = require('./src/batch'); | |
var oldRedis = redis.createClient(6379 , 'sourceip'); | |
var newRedis = redis.createClient(6379 , 'targetip'); | |
oldRedis.auth('pwdifany'); | |
newRedis.auth('pwdifany'); | |
oldRedis.select(0); | |
newRedis.select(0); | |
var count = 0; | |
db.init(function(err) { | |
if (err) { | |
console.log("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message); | |
process.exit(); | |
} | |
batch.processSortedSet('users:joindate', function(uids, next) { | |
async.each(uids, processUid, function(err) { | |
if (err) { | |
return next(err); | |
} | |
count += uids.length; | |
console.log('finished ' + count); | |
next(); | |
}); | |
}, function(err) { | |
if (err) { | |
console.log(err); | |
process.exit(); | |
return; | |
} | |
console.log('done'); | |
}); | |
}); | |
function processUid(uid, next) { | |
async.parallel({ | |
oldValue: function(next) { | |
oldRedis.get('hp:' + uid, next); | |
}, | |
newValue: function(next) { | |
newRedis.get('hp:' + uid, next); | |
} | |
}, function(err, results) { | |
if (err) { | |
return next(err); | |
} | |
var oldValue = parseInt(results.oldValue, 10) || 0; | |
var newValue = parseInt(results.newValue, 10) || 0; | |
if (oldValue + newValue > 0) { | |
console.log(uid, oldValue + newValue); | |
newRedis.set('hp:' + uid, oldValue + newValue, next); | |
} else { | |
next(); | |
} | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment