A session module that uses Object.observe() to set values to Redis atomically and asynchronously.
Usage:
const app = require('koa')()
require('session')(app, {
uri: 'tcp://localhost:6379'
})
app.use(function* (next) {
try {
yield* next
} catch (err) {
throw err
} finally {
// always give time for `Object.observe()` to do its thing
yield setImmediate
}
})
app.use(function* (next) {
let session = yield this.session()
session.userid = '1234'
yield* next
})Adds this.session() to the app.
Options:
-
.uri- Redis URI -
.client- Redis client, if not set by.uri -
.length- session id key byte length, default10 -
.prefix- Redis key prefix, defaulthash:koa-session: -
.maxAge- max session age, default30 days
Grab the session asynchronously.
Update the session without changing the values on the server.
Destroy the session.
Destroy the old session and return a new one.
Set the max age for this session, defaulting to options.maxAge.
- You must always
yield setImmediateupstream to allowObject.observe()time to execute its callback.