https://github.com/leaguedevelopers/pow-pow
Redis backed rate limiter for the Riot API
https://github.com/leaguedevelopers/pow-pow
api leagueoflegends ratelimiter redis riot riot-api typescript
Last synced: 3 months ago
JSON representation
Redis backed rate limiter for the Riot API
- Host: GitHub
- URL: https://github.com/leaguedevelopers/pow-pow
- Owner: LeagueDevelopers
- License: mit
- Created: 2017-09-01T23:16:46.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-01T23:23:40.000Z (about 8 years ago)
- Last Synced: 2025-02-13T13:05:05.572Z (8 months ago)
- Topics: api, leagueoflegends, ratelimiter, redis, riot, riot-api, typescript
- Language: TypeScript
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Pow Pow
A Rate Limiter backed by Redis for use with Riot API projects
`npm i --save pow-pow`
## Usage
```ts
const redis = require('redis');
// see src/regions.ts for valid regions
const limiter = new RateLimiter('euw', '20:1,2000:60', redis.createClient());
// init() loads the Lua scripts to Redis
limiter.init().then(() => {
// see src/limits.ts for default methods
// you can also pass no arguments to not use a method limit
limiter.addRequest('GET_MATCH')
.then(limiterResults => {
// proceed with your request
// ...// optionally you may inspect the rate limiter result objects
limiterResults.forEach(res => {
const {key, remaining, total, reset} = res;
})
})
.catch(err => {
if (err.hasOwnProperty('after')) {
// Rate limit was hit, reset is in epoch miliseconds
const {key, after, reset} = err;console.log(`${key} limiter was hit, retry after ${after} seconds`);
}
})
});
```