hot-api.js
793 Bytes
const redis = global.yoho.redis;
const logger = global.yoho.logger;
const utils = require('./utils');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
async getIndex() {
const keys = [];
for await (const item of utils.createAsyncKeyIterable('global:yoho:seo:hot:keywords:allIds:page:')) {
keys.push(item.key)
}
return keys;
}
async getIds(page) {
return redis.getAsync(`global:yoho:seo:hot:keywords:allIds:page:${page}`).then(data => {
if (data) {
return JSON.parse(data);
}
return [];
}).catch(() => {
logger.error(`redis get keys hot page ${page}`);
return [];
});
}
};