Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

kk-koa-framework

Package Overview
Dependencies
170
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.57 to 2.0.1

src/middleware/fastCache.js

2

package.json

@@ -6,3 +6,3 @@ {

"name": "kk-koa-framework",
"version": "1.0.57",
"version": "2.0.1",
"description": "kk koa mvc webframework",

@@ -9,0 +9,0 @@ "main": "index.js",

@@ -1,102 +0,10 @@

const {
randomBytes
} = require('crypto')
const Redis = require('ioredis')
const debug = require('debug')('kk:session')
const {RedisClient,RedisStore} = require('./redis')
module.exports = (session = {}) => {
let {
port,
host,
password,
db,
ttl,
prefix
} = session || {}
let redis = RedisClient.create(session,session.key).client
let redis = null,
pingSi, config = {}
port && (config.port = port)
host && (config.host = host)
password && (config.password = password)
db && (config.db = db)
const connect = () => {
redis = new Redis({
port,
host,
password,
db,
})
redis.on('error', (e) => {
console.error('redis connect error:', e)
try {
redis.end()
} catch (e) {
console.error(e)
}
redis = null
connect()
})
redis.ping()
pingSi && clearInterval(pingSi)
pingSi = setInterval(function () {
redis.ping()
}, 60 * 1000)
}
connect()
class RedisStore {
constructor() {
this.sessions = new Map()
this.__timer = new Map()
this.ttl = ttl
this.redis = redis
this.prefix = prefix || 'SESSION'
}
getID(length) {
return randomBytes(length).toString('hex')
}
async get(sid) {
let id = `${this.prefix}:${sid}`
let data = await this.redis.get(id)
data && this.ttl && this.redis.expire(id, this.ttl)
return JSON.parse(data)
}
async set(session, {
sid = this.getID(24)
} = {}) {
try {
let id = `${this.prefix}:${sid}`
await this.redis.set(id, JSON.stringify(session))
this.ttl && this.redis.expire(id, this.ttl)
} catch (e) {
console.error(e)
}
return sid
}
async refresh(sid){
let id = `${this.prefix}:${sid}`
this.ttl && this.redis.expire(id, this.ttl)
}
async destroy(sid) {
return await this.redis.del(`${this.prefix}:${sid}`)
}
}
return async (ctx, next) => {

@@ -111,4 +19,5 @@

const key = 'kk:session'
const store = new RedisStore()
const store = new RedisStore(redis,session)
let opts = {}

@@ -115,0 +24,0 @@

@@ -8,9 +8,21 @@ const fs = require('fs')

let Session = require(path.join(__dirname,'../middleware/session'))
let FastCache = require(path.join(__dirname,'../middleware/fastCache'))
let Redis = require(path.join(__dirname,'../middleware/redis'))
app.use(I18n(app.$$.CONFIG_DIR))
app.use(require(path.join(__dirname,'../middleware/cookie')))
if(app.$$.config.session !== false){
if(app.$$.config.redis){
Redis && Redis.RedisClient.create(app.$$.config.redis,'redis')
}
if(app.$$.config.session){
app.use(Session(app.$$.config.session))
}
if(app.$$.config.fastCache){
app.use(FastCache(app.$$.config.fastCache))
}
let dir = path.join(app.$$.SOURCE_DIR,'middleware')

@@ -17,0 +29,0 @@

module.exports = {
redis:{
host:'127.0.0.1',
db:1,
},
session:{},
fastCache:{
}
}

@@ -7,2 +7,3 @@ const {passport} = require('../../../index')

ctx.session.save()
ctx.cache.set('1312',{})
ctx.body = '11'

@@ -9,0 +10,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc