76 lines
1.6 KiB
JavaScript
76 lines
1.6 KiB
JavaScript
var Redis = require('ioredis');
|
|
var mongoose = require('mongoose');
|
|
|
|
var db,
|
|
lastLoginModel,
|
|
redis;
|
|
|
|
var quit = function() {
|
|
if (redis ) {
|
|
redis.quit();
|
|
};
|
|
|
|
console.log("Mongoose status:", mongoose.connection.readyState);
|
|
|
|
mongoose.disconnect(function() {
|
|
console.log('Mongoose disconnected on app termination');
|
|
});
|
|
};
|
|
|
|
var open = function() {
|
|
var mongoReplicaSet = 'mongodb://mongo-1.mail.tiscali.sys:27018, mongo-3.mail.tiscali.sys:27018, mongo-5.mail.tiscali.sys:27018';
|
|
|
|
var Schema = mongoose.Schema;
|
|
|
|
var lastLoginSchema = new Schema({
|
|
user: String,
|
|
ip: String,
|
|
protocol: String,
|
|
date: Date,
|
|
});
|
|
|
|
lastLoginModel = mongoose.model('lastLogin', lastLoginSchema);
|
|
|
|
redis = new Redis('redis://redis-ll.mail.tiscali.sys:6379/0');
|
|
|
|
db = mongoose.createConnection(mongoReplicaSet, { mongos: true } );
|
|
}
|
|
|
|
var readLog = function(user) {
|
|
|
|
};
|
|
|
|
open();
|
|
|
|
redis.spop('llindex', function(err, user){
|
|
if( err != null) {
|
|
console.log(err);
|
|
quit();
|
|
process.exit(-1);
|
|
}
|
|
|
|
redis.llen(user, function(err, len){
|
|
var readLogs = function(index) {
|
|
if (index == (len-1) ){
|
|
console.log("Done: ", index);
|
|
quit();
|
|
} else {
|
|
redis.rpop(user, function(err, log){
|
|
if ( err != null ) {
|
|
console.log(err);
|
|
quit();
|
|
process.exit(-1);
|
|
}
|
|
|
|
console.log("Log: ", index, log);
|
|
readLogs(index+1);
|
|
})
|
|
};
|
|
};
|
|
if(user != null) {
|
|
readLogs(0);
|
|
} else {
|
|
quit();
|
|
}
|
|
});
|
|
});
|