commit 195002ca0ff5ddbf9f2e74b06cb8403a65225696 Author: Michele Fadda Date: Tue May 26 10:47:04 2015 +0200 loop ricorsivo diff --git a/llmongo.js b/llmongo.js new file mode 100644 index 0000000..4c5d953 --- /dev/null +++ b/llmongo.js @@ -0,0 +1,76 @@ +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(); + } + }); +});