koa-session-redis-store
This is a redis store module for koa-session.
It can be used like this:
const session = require('koa-session');
const RedisStore = require('koa-session-redis-store');
const Koa = require('koa');
const app = new Koa();
app.keys = ['some secret hurr'];
const CONFIG = {
store: new RedisStore(),
// The others options for koa-session
};
app.use(session(CONFIG, app));
app.use(ctx => {
// ignore favicon
if (ctx.path === '/favicon.ico') return;
let n = ctx.session.views || 0;
ctx.session.views = ++n;
ctx.body = n + ' views';
});
app.listen(3000);
Install
$ npm install koa-session-redis-store
API
Constructor
const redisStore = new RedisStore(opts);
opts: The options that will be passed to redis client(node_redis).
Events
It could catch the events from where redis client.
redisStore.on('ready', function() {
});
redisStore.on('connect', function() {
});
redisStore.on('reconnecting', function(reconnectParams) {
});
redisStore.on('error', function(err) {
});
redisStore.on('end', function() {
});
redisStore.on('warning', function(msg) {
});
Close connection
Close function is executed as asynchrous by using bluebird.
redisStore.close()
.delay(1000) // It allows to use the bluebird api
.then(function(result) {
console.log(result);
});
or also can be called using async/await.
const close = async () => {
const result = await redisStore.close();
console.log(result);
};
License
MIT