tj / connect-redis

Redis session store for Connect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ttl always gets millisecond value when session expiry is set

arfeen opened this issue · comments

ttl is getting a wrong value (or actually millisecond value) when session expiry is already set.

Take a look at this

if (!this.disableTTL) {
        ttl = this._getTTL(sess)
        args.push("EX", ttl)
      }

"EX" expects the seconds value not the millisecond, but then see the this._getTTL(sess) :

if (sess && sess.cookie && sess.cookie.expires) { 
        let ms = Number(new Date(sess.cookie.expires)) - Date.now()
        ttl = Math.ceil(ms / 1000)
      } else {
        ttl = this.ttl
      }

I believe this should not divide by 1000 since later it will be stored with "EX" argument in Redis .

Please correct me, but I feel that is a bug.

  1. the docs saids ttl is the time in seconds. Thus I believe _getTTL should return the time in seconds
  2. ms / 1000 is there to convert from milliseconds to seconds (as expected by EX)

I didn't get what's wrong

  1. the docs saids ttl is the time in seconds. Thus I believe _getTTL should return the time in seconds
  2. ms / 1000 is there to convert from milliseconds to seconds (as expected by EX)

I didn't get what's wrong

You are right. That was a mistake by me. I just realized, I was setting "second" value in "maxAge" in express-session instead millisecond.

It's all working fine. Closing the issue.