Skip to content

trekjs/sessions-provider-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sessions-provider-redis

Sessions Redis Provider

Install

$ npm install sessions-provider-redis --save

Usage

'use strict'

const Engine = require('trek-engine')
const sessions = require('trek-sessions')
const RedisProvider = require('sessions-provider-redis')

async function start (port = 3000) {
  const app = new Engine()

  app.config.set('cookie', {
    keys: ['trek', 'engine']
  })

  app.use(await sessions({
    cookie: {
      signed: false,
      maxAge: 60 * 1000 // 1 minutes
    },
    provider: new RedisProvider()
  }))

  app.use(async ctx => {
    if (ctx.session.count) {
      ctx.session.count++
    } else {
      ctx.session.count = 1
    }
    if (ctx.req.path === '/clear') {
      ctx.session = null
      await ctx.sessions.store.clear()
    }
    ctx.res.body = ctx.session
  })

  await app.run(port)
}

start().catch(console.error)

API

  • get(sid)

  • set(sid, sess, expires)

  • has(sid)

  • delete(sid)

  • clear()

  • quit()

Badges

NPM version MIT License Codecov Linux Build Window Build


fundon.me  ·  GitHub @Fangdun Cai  ·  Twitter @_fundon

About

Sessions Redis Provider

Resources

License

Stars

Watchers

Forks

Packages

No packages published