node express session怎么用
1个回答
推荐于2016-10-24 · 知道合伙人软件行家
关注
展开全部
1:存储到内存中
var session = require('express-session');
app.use(session({
secret: configs.sysconfig.sessionsecret,
key: configs.sysconfig.sessionsid,
cookie: {
secret: true,
expires: false
},
resave: true,
saveUninitialized: true
}));
2:存储到redis
app.use(session({
store: new RedisStore({
host: "127.0.0.1",
port: 6379,
db: "test_session"
}),
resave:false,
saveUninitialized:false,
secret: 'keyboard cat'
}))
3:存储到mongodb
app.use(session({
secret: config.session_opts.sessionsecret,
store: new MongoStore({
url: config.session_opts.db
}),
resave: true,
saveUninitialized: true
}));
var session = require('express-session');
app.use(session({
secret: configs.sysconfig.sessionsecret,
key: configs.sysconfig.sessionsid,
cookie: {
secret: true,
expires: false
},
resave: true,
saveUninitialized: true
}));
2:存储到redis
app.use(session({
store: new RedisStore({
host: "127.0.0.1",
port: 6379,
db: "test_session"
}),
resave:false,
saveUninitialized:false,
secret: 'keyboard cat'
}))
3:存储到mongodb
app.use(session({
secret: config.session_opts.sessionsecret,
store: new MongoStore({
url: config.session_opts.db
}),
resave: true,
saveUninitialized: true
}));
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询