Showing
1 changed file
with
5 additions
and
11 deletions
@@ -26,16 +26,10 @@ module.exports = (limiter, policy) => { | @@ -26,16 +26,10 @@ module.exports = (limiter, policy) => { | ||
26 | }); | 26 | }); |
27 | 27 | ||
28 | return cache.getMultiAsync(_.values(ruleKeys)).then((results) => { | 28 | return cache.getMultiAsync(_.values(ruleKeys)).then((results) => { |
29 | - logger.debug(results); | ||
30 | - | ||
31 | - // 第一次访问 | ||
32 | - if (_.isEmpty(results)) { | ||
33 | - _.forEach(MAX_TIMES, (val, key) => { | ||
34 | - cache.setAsync(ruleKeys[key], 1, +key); // eslint-disable-line | ||
35 | - }); | ||
36 | 29 | ||
37 | - return Promise.resolve(true); | ||
38 | - } | 30 | + logger.debug(MAX_TIMES); |
31 | + logger.debug(_.values(ruleKeys)); | ||
32 | + logger.debug(results); | ||
39 | 33 | ||
40 | // 遍历限制规则,若满足返回相应处理策略, 否则页面访问次数加1 | 34 | // 遍历限制规则,若满足返回相应处理策略, 否则页面访问次数加1 |
41 | _.forEach(MAX_TIMES, (val, key) => { | 35 | _.forEach(MAX_TIMES, (val, key) => { |
@@ -48,9 +42,9 @@ module.exports = (limiter, policy) => { | @@ -48,9 +42,9 @@ module.exports = (limiter, policy) => { | ||
48 | // ip限制1小时 | 42 | // ip限制1小时 |
49 | cache.setAsync(`${config.app}:limiter:${limiter.remoteIp}`, 1, limiterIpTime); | 43 | cache.setAsync(`${config.app}:limiter:${limiter.remoteIp}`, 1, limiterIpTime); |
50 | return Promise.resolve(policy); | 44 | return Promise.resolve(policy); |
45 | + } else { | ||
46 | + cache.incrAsync(cacheKey, 1); | ||
51 | } | 47 | } |
52 | - | ||
53 | - cache.incrAsync(cacheKey, 1); | ||
54 | }); | 48 | }); |
55 | 49 | ||
56 | // 不满足任何限制规则,继续访问 | 50 | // 不满足任何限制规则,继续访问 |
-
Please register or login to post a comment