const router = require('koa-router')() //导入 koa-router
const redis = require("../model/redis_db")  //导入 db.js
// https://github.com/luin/ioredis#readme


router.prefix('/test/redis');
router.post('/set', async (ctx) => {
    const obj = ctx.request.body;
    console.log("set:",obj)
    redis.redis_set(obj.key, obj.value);
    ctx.body = obj.key + " - "+ obj.value
})

router.post('/get', async (ctx) => {
    const obj = ctx.request.body;
    console.log("get:",obj)
    await redis.redis_get(obj.key).then((result) => {
        ctx.body = "key:" + obj.key + " \n" + "value:" + result
    });
})
module.exports = router

