Skip to content

Commit

Permalink
Add ttl interception for conditional ttl handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Movwf committed May 9, 2023
1 parent f390403 commit f94cb89
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface RedisStoreOptions {
prefix?: string
scanCount?: number
serializer?: Serializer
ttl?: number
ttl?: number | {(sess: SessionData): number}
disableTTL?: boolean
disableTouch?: boolean
}
Expand All @@ -31,7 +31,7 @@ class RedisStore extends Store {
prefix: string
scanCount: number
serializer: Serializer
ttl: number
ttl: number | {(sess: SessionData): number}
disableTTL: boolean
disableTouch: boolean

Expand Down Expand Up @@ -181,6 +181,10 @@ class RedisStore extends Store {
}

private _getTTL(sess: SessionData) {
if (typeof this.ttl === "function") {
return this.ttl(sess)
}

let ttl
if (sess && sess.cookie && sess.cookie.expires) {
let ms = Number(new Date(sess.cookie.expires)) - Date.now()
Expand Down

0 comments on commit f94cb89

Please sign in to comment.