Authored by 周少峰

first del

... ... @@ -26,16 +26,10 @@ module.exports = (limiter, policy) => {
});
return cache.getMultiAsync(_.values(ruleKeys)).then((results) => {
logger.debug(results);
// 第一次访问
if (_.isEmpty(results)) {
_.forEach(MAX_TIMES, (val, key) => {
cache.setAsync(ruleKeys[key], 1, +key); // eslint-disable-line
});
return Promise.resolve(true);
}
logger.debug(MAX_TIMES);
logger.debug(_.values(ruleKeys));
logger.debug(results);
// 遍历限制规则,若满足返回相应处理策略, 否则页面访问次数加1
_.forEach(MAX_TIMES, (val, key) => {
... ... @@ -48,9 +42,9 @@ module.exports = (limiter, policy) => {
// ip限制1小时
cache.setAsync(`${config.app}:limiter:${limiter.remoteIp}`, 1, limiterIpTime);
return Promise.resolve(policy);
}
} else {
cache.incrAsync(cacheKey, 1);
}
});
// 不满足任何限制规则,继续访问
... ...