(identifier: string, rate = 1)
| 45 | } |
| 46 | |
| 47 | async limit(identifier: string, rate = 1): Promise<RateLimitResponse> { |
| 48 | const result = this.#ratelimit.limit(identifier, { rate }); |
| 49 | const { success, limit, reset, remaining } = await result; |
| 50 | |
| 51 | if (success && this.options.logSuccess) { |
| 52 | logger.info(`RateLimiter (${this.options.keyPrefix}): under rate limit`, { |
| 53 | limit, |
| 54 | reset, |
| 55 | remaining, |
| 56 | identifier, |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | //log these by default |
| 61 | if (!success && this.options.logFailure !== false) { |
| 62 | logger.info(`RateLimiter (${this.options.keyPrefix}): rate limit exceeded`, { |
| 63 | limit, |
| 64 | reset, |
| 65 | remaining, |
| 66 | identifier, |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | return result; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | export function createRedisRateLimitClient( |
no test coverage detected