-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
46 lines (39 loc) · 884 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Created by koala on 2016/9/14.
*/
'use strict';
const redis = require('ioredis');
const db = redis.createClient();
const Limit = require('./');
const interfaceIdArray= ['_300', '_550'];
const id = '23333';
const limiter_300 = new Limit({
id: id,
db: db,
interfaceId: interfaceIdArray[0]
});
const limiter_550 = new Limit({
id: id,
db: db,
interfaceId: interfaceIdArray[1]
});
// 模拟请求(300毫秒一次)
setInterval(() => {
limiter_300.check((err, data) => {
if (err) {
console.log('err', err);
} else {
console.log('data', data);
}
});
}, 300);
// 模拟请求(550毫秒一次)
setInterval(() => {
limiter_550.check((err, data) => {
if (err) {
console.log('err', err);
} else {
console.log('data', data);
}
});
}, 550);