rl

request-limit

通过redis缓存实现token对url的访问频率控制

Showing:

Popularity

Downloads/wk

2

GitHub Stars

2

Maintenance

Last Commit

4yrs ago

Contributors

2

Package

Dependencies

1

Size (min+gzip)

16.7KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

通过redis缓存实现token对url的访问频率控制

token可为登录用户的ticket

安装

$ npm install request-limit

初始化

const limit = require('request-limit')
const urlMap = new Map()
urlMap.set('/api/user/getList.get', {limit: 2, interval: 20})
urlMap.set('/api/user/add.post', {limit: 2, interval: 2})
urlMap.set('/api/user/getOne.get', {limit: 2, interval: 2})

// 白名单
const whiteList = []
whiteList.push('/api/login.post')

limit.init(urlMap, {
    store: {
        host: '127.0.0.1',
        port: 6379
    },
    whiteList
})

其中,后面的参数为多少秒内访问多少次

如果不在urlMap里面设置,则使用默认配置24小时内访问1000次

在白名单中的url不受限制

使用

const limitRlt = await limit.checkLimit('token', 'url.post')
await limit.record('token', 'url.post')

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100