UNPKG

redis-sliding-rate-limiter

Version:

Flexible and performant rate limiter based on sliding window algorithm with arbitrary precision

25 lines (24 loc) 841 B
import { RateLimiter, RateLimiterResponse } from '../RateLimiter'; export declare abstract class Strategy { limiter: RateLimiter; scriptSha1?: string; constructor(limiter: RateLimiter); /** * Wrapper for sending command to Redis * @param cmd {string} Redis command * @param args {any[]} Arguments * @returns {Promise<any>} */ abstract sendCommand(cmd: string, ...args: any[]): Promise<any>; /** * Load script on Redis cache and returns sha1 of the script * @returns {Promise<string>} */ abstract loadScript(): Promise<string>; /** * Call script execution on Redis using EVALSHA. Loads script on Redis cache if needed. * @param key {any} * @returns {Promise<RateLimiterResponse>} */ abstract execScript(key: any): Promise<RateLimiterResponse>; }