2017-03-27 15:36:45 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('config');
|
2017-04-05 16:39:42 +08:00
|
|
|
const tools = require('./tools');
|
2017-03-27 15:36:45 +08:00
|
|
|
const mongodb = require('mongodb');
|
2017-04-05 16:39:42 +08:00
|
|
|
const redis = require('redis');
|
2017-03-27 15:36:45 +08:00
|
|
|
const MongoClient = mongodb.MongoClient;
|
|
|
|
|
|
|
|
module.exports.database = false;
|
2017-04-05 16:39:42 +08:00
|
|
|
module.exports.redis = false;
|
2017-03-27 15:36:45 +08:00
|
|
|
|
|
|
|
module.exports.connect = callback => {
|
|
|
|
MongoClient.connect(config.mongo, (err, database) => {
|
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
module.exports.database = database;
|
2017-04-05 16:39:42 +08:00
|
|
|
module.exports.redis = redis.createClient(tools.redisConfig(config.redis));
|
2017-03-27 15:36:45 +08:00
|
|
|
callback(null, database);
|
|
|
|
});
|
|
|
|
};
|