Thu Jan 26 2017
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
import {Store} from 'koa-session2'


export default class memstore extends Store {

  constructor()
  {
    super()
    this.store = {}
  }

  get(sid)
  {
    const data = this.store[`SESSION:${sid}`]
    return JSON.parse(data)
  }


  set(session, opts)
  {
    if (!opts.sid)
    {
      opts.sid = this.getID(24)
    }

    this.store[`SESSION:${opts.sid}`] = JSON.stringify(session)
    return opts.sid
  }


  destroy(sid)
  {
    delete this.store[`SESSION:${sid}`]
  }

}