Skip to content

Commit

Permalink
Add documentation for disableTTL feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wavded committed Feb 8, 2021
1 parent ba2c99f commit 8993263
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ jobs:
node-version: ${{ matrix.node }}
- run: sudo apt-get install -y redis-server
- run: yarn install
- run: yarn fmt-check
- run: yarn lint
- run: yarn test
10 changes: 4 additions & 6 deletions lib/connect-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function (session) {
this.serializer = options.serializer || JSON
this.client = options.client
this.ttl = options.ttl || 86400 // One day in seconds.
this.disableTTL = options.disableTTL || false
this.disableTTL = options.disableTTL || false
this.disableTouch = options.disableTouch || false
}

Expand Down Expand Up @@ -54,22 +54,20 @@ module.exports = function (session) {
return cb(er)
}
args.push(value)
if(!this.disableTTL) args.push('EX', this._getTTL(sess))
if (!this.disableTTL) args.push('EX', this._getTTL(sess))

this.client.set(args, cb)
}

touch(sid, sess, cb = noop) {
if (this.disableTouch) return cb()
if(!this.disableTTL) {
if (this.disableTouch || this.disableTTL) return cb()
let key = this.prefix + sid
this.client.expire(key, this._getTTL(sess), (err, ret) => {
if (err) return cb(err)
if (ret !== 1) return cb(null, 'EXPIRED')
cb(null, 'OK')
})
} else cb(null, 'OK')
}
}

destroy(sid, cb = noop) {
let key = this.prefix + sid
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ The `express-session` package uses `touch` to signal to the store that the user

Ref: https://github.com/expressjs/session#storetouchsid-session-callback

##### disableTTL

Disables key expiration completely (default: `false`)

This option disables key expiration requiring the user to manually manage key cleanup outside of `connect-redis`. Only use if you know what you are doing and have an exceptional case where you need to manage your own expiration in Redis. Note this has no effect on `express-session` setting cookie expiration.

##### serializer

The encoder/decoder to use when storing and retrieving session data from Redis (default: `JSON`).
Expand Down
1 change: 1 addition & 0 deletions test/connect-redis-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test('defaults', async (t) => {
t.equal(store.scanCount, 100, 'defaults SCAN count to 100')
t.equal(store.serializer, JSON, 'defaults to JSON serialization')
t.equal(store.disableTouch, false, 'defaults to having `touch` enabled')
t.equal(store.disableTTL, false, 'defaults to having `ttl` enabled')
client.end(false)
})

Expand Down

0 comments on commit 8993263

Please sign in to comment.