nodeclub百度云部署成功,session采用百度云的resdis服务
session设置代码:session换用redis代替mongodb
var session = require('express-session'); var redis = require('redis');
var RedisStore = require('connect-redis')(session);
var client = redis.createClient(80, 'redis.duapp.com', {"no_ready_check":true});
client.on("error", function (err) {
console.log("Error " + err);
});
/ /*数据库连接信息host,port,user,pwd,dbname(可查询数据库详情页)*/
var username = 'UrtgxzMPVigNEyOQF7yzg7C9'; // 用户名(API KEY)
var password = '1e0jDqkZ7fUwNGFD5LzwPY4YAQURFGYM'; // 密码(Secret KEY)
var db_host = 'redis.duapp.com';
var db_port = 80;
var db_name = 'QTQTzJQhMKcabjpSTIEX'; // 数据库名
console.log(db_host);
console.log(db_port);
var options = {"no_ready_check":true};
// 建立连接后,在进行集合操作前,需要先进行auth验证
client.auth(username + '-' + password + '-' + db_name);
app.use(session({
secret: config.session_secret,
key: 'sid',
store: new RedisStore({
client:client
}),
resave: true,
saveUninitialized: true
}