0.4.6 • Published 5 years ago
@iinfinity/redion v0.4.6
Redion
Session with redis storage or local storage.
Description
This is a koa session middleware with redis / local storage and TypeScript supported, use in Rester server framework on NPM.
Change Log
0.4.5 => 0.4.6
- chore: move @types/ioredis to dev
0.3.4 => 0.4.0
- feat: local storage support
- refactor: refactor redis storage support
- refactor: refactor class Redion
Usage
For Koa
import { Option, Redion } from '@iinfinity/redion';
import Koa from 'koa'; // import koa
const koa = new Koa(/** ... */);
const option: Option = {
domain: 'your.domain.com',
expire: 1000, // second
koa, // your koa instance, for signing cookie
name: 'session.id', // cookie key of session id
secert: ['your', 'secert', 'keys'] // signed your cookie with this array
};
koa.use(new Redion(option).ware);
For Rester
import { Option, Redion } from '@iinfinity/redion';
import Rester from '@iinfinity/rester'; // import rester
const rester = new Rester(/** ... */);
const option: Option = {
domain: 'your.domain.com',
expire: 1000, // second
koa: rester.app, // your koa instance, for signing cookie
name: 'session.id', // cookie key of session id
secert: ['your', 'secert', 'keys'] // signed your cookie with this array
};
rester.use({
'redis session middleware': new Redion(option).ware
});
Option
See the source code of the Session interface.
/** Session middleware option. */
export interface Option {
/** Cookie domain. */
domain: string;
/** Expire time, second. */
expire: number;
/** File storage, for local only. */
file?: string;
/** Koa instance for signing cookie. */
koa: Koa;
/** Cookie name of session id. */
name: string;
/** Redis connection options. */
redis?: RedisOptions;
/** Signed your cookie with this array. */
secert: string[];
}