An open API service indexing awesome lists of open source software.

https://github.com/trekjs/sessions-provider-redis

Sessions Redis Provider
https://github.com/trekjs/sessions-provider-redis

Last synced: 6 days ago
JSON representation

Sessions Redis Provider

Awesome Lists containing this project

README

        

# sessions-provider-redis

> Sessions Redis Provider

## Install

```console
$ npm install sessions-provider-redis --save
```

## Usage

```js
'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](https://fundon.me)  · 
> GitHub [@Fangdun Cai](https://github.com/fundon)  · 
> Twitter [@_fundon](https://twitter.com/_fundon)