Skip to content

Commit

Permalink
Added ttl option, which comes prior to cookie maxAge. Now session ttl…
Browse files Browse the repository at this point in the history
… is (options.ttl, cookie.maxAge, oneDay) whichever defined first.

If options.ttl is not defined, previous behaviour is preserved.
  • Loading branch information
SlNPacifist committed Jun 14, 2012
1 parent c4d2941 commit 5a6c559
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/connect-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ module.exports = function(connect){
});
}

this.ttl = options.ttl;

if (options.db) {
var self = this;
self.client.select(options.db);
Expand Down Expand Up @@ -108,10 +110,11 @@ module.exports = function(connect){
sid = this.prefix + sid;
try {
var maxAge = sess.cookie.maxAge
, ttl = 'number' == typeof maxAge
, ttl = this.ttl
, sess = JSON.stringify(sess);
if (ttl == null) ttl = 'number' == typeof maxAge
? maxAge / 1000 | 0
: oneDay
, sess = JSON.stringify(sess);

debug('SETEX "%s" ttl:%s %s', sid, sess);
this.client.setex(sid, ttl, sess, function(err){
Expand Down

0 comments on commit 5a6c559

Please sign in to comment.