keywords.js 1.27 KB
/**
 *
 * @author: shijian<jian.shi@yoho.cn>
 * @date: 17/5/31
 */

'use strict';

const Router = require('koa-router');
const moment = require('moment');
const redisStore = require('koa-redis');
const redis = require("redis");
const client = redis.createClient();
const multi = client.multi();

client.on("error", function (err) {
    console.log("Error " + err);
});

const {
    OperationLogger
} = require('../../models');

const r = new Router();

const setData = ()=>{
    client.set('keywords_mana:aaa', 'aaa');
    client.set('keywords_mana:bbb', 'bbb');
    let arr = ['keywords_mana:aaa', 'keywords_mana:bbb'];

    for (var i=0; i<arr.length; i++) {
        multi.sadd('keywords_mana_list', arr[i]);
    }

    multi.exec(function(errors, results) {

    });
}

const getData = async(key)=>{
    multi.smembers(key);
    return new Promise(function (resolve, reject) {
        multi.exec(function(errors, results) {
            resolve(results);
        });
    });
}

r.get('/', async(ctx) => {
    await ctx.render('action/keywords');
});

r.get('/getKeywords', async(ctx) => {

    let q = ctx.request.query;
    
    let r = await getData("keywords_mana_list");
    
    ctx.body = {
        code: 200,
        message: 'success',
        data: r[0]
    };
    

});

module.exports = r;