Commit e668f9e2 authored by 姜登's avatar 姜登

nodelimit

parent 88c37c6f
Pipeline #7114 passed with stage
in 4 seconds
......@@ -144,6 +144,50 @@ class PartnerService extends Service {
}
return;
}
async appKeyLimit(appKey) {
const { ctx, partnerAPI: { redisappKeyLimitPrefix } } = this;
let data = await this.app.redis.get(redisappKeyLimitPrefix);
if (data) {
data = JSON.parse(data);
if (data.includes(appKey)) {
let limit = await this.app.redis.get(redisappKeyLimitPrefix + appKey);
if (limit) {
limit = JSON.parse(limit);
if (limit.currentCount >= limit.limitCount) {
ctx.throw(422, { message: 'appKey查询数量超过限制,请联系技术人员' });
} else {
// limit.currentCount++;
// await this.app.redis.set(redisappKeyLimitPrefix + appKey, JSON.stringify({ currentCount: limit.currentCount, limitCount: limit.limitCount }), 'EX', 300);
await ctx.model.query('UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?', {
type: 'UPDATE',
replacements: [appKey],
});
}
}
}
} else {
const dbRes = await ctx.model.NodeLimit.findAll({
attributes: ['appKey', 'currentCount', 'limitCount'],
where: { type: 'yys' },
});
if (dbRes) {
const appKeyArray = [];
for (const item of dbRes) {
const { appKey, currentCount, limitCount } = item;
appKeyArray.push(appKey);
await this.app.redis.set(redisappKeyLimitPrefix + appKey, JSON.stringify({ currentCount, limitCount }), 'EX', 300);
}
await this.app.redis.set(redisappKeyLimitPrefix, JSON.stringify(appKeyArray), 'EX', 300);
if (appKeyArray.includes(appKey)) {
await ctx.model.query('UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?', {
type: 'UPDATE',
replacements: [appKey],
});
}
}
}
}
}
module.exports = PartnerService;
......@@ -39,6 +39,7 @@ module.exports = () => {
redisAgreementsPrefix: 'URANUS.YYS.PARNTERS.Agreements',
fetchInfo: '/chaos/partner',
redisInfoPrefix: 'URANUS.YYS.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.YYS.PARNTERS.Limit',
};
config.scriptsAPI = {
......
......@@ -84,6 +84,7 @@ module.exports = () => {
redisAgreementsPrefix: 'URANUS.YYS.PARNTERS.Agreements',
fetchInfo: '/chaos/partner',
redisInfoPrefix: 'URANUS.YYS.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.YYS.PARNTERS.Limit',
};
config.lockKeys = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment