I'm doing it like this:
app.use(express.session({
cookie:{domain:"."+settings.c.SITE_DOMAIN},
secret:'abc',
store: redis_store,
}));
When I log into my redis and type TTL sess:...
, it seems that there is an expiration on this session.
How can I make the sessions never expire? (for everything). I also want the cookies to never expire.
I'm doing it like this:
app.use(express.session({
cookie:{domain:"."+settings.c.SITE_DOMAIN},
secret:'abc',
store: redis_store,
}));
When I log into my redis and type TTL sess:...
, it seems that there is an expiration on this session.
How can I make the sessions never expire? (for everything). I also want the cookies to never expire.
Share asked Jan 21, 2012 at 6:48 TIMEXTIMEX 273k368 gold badges802 silver badges1.1k bronze badges 3- 3 Cookies (including session cookies) cannot have infinite expiration dates. The largest you can get, practically, is a date in 2038... after that you'll overflow the timestamp field. – Dan Grossman Commented Jan 21, 2012 at 6:52
- OK, sure that works. How do I set it to 2038? – TIMEX Commented Jan 21, 2012 at 11:44
- 3 @TIMEX never expiring is silly. – Raynos Commented Jan 21, 2012 at 12:26
1 Answer
Reset to default 4As mentioned in the Connect guide on the session middleware page (Express uses Connect internally), you can specify a maxAge option on sessions:
- cookie Session cookie settings, defaulting to { path: '/', httpOnly: true, maxAge: 14400000 }
Example:
connect(
connect.cookieParser()
, connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})
, connect.favicon()
, function(req, res, next){
var sess = req.session;
if (sess.views) {
res.setHeader('Content-Type', 'text/html');
res.write('<p>views: ' + sess.views + '</p>');
res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>');
res.end();
sess.views++;
} else {
sess.views = 1;
res.end('wele to the session demo. refresh!');
}
}
).listen(3000);
Note: maxAge is in milliseconds, so for example a day = 86400000
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745045632a4608079.html
评论列表(0条)