Skip to main content
Version: Next

Ratelimit

ratelimit

Convenience function to check if a request is allowed for a given key. Uses the default rate limiter instance.

Example

const allowed = await ratelimit('user:123');
// update the default rate limiter config
import { defaultRateLimiter } from 'commandkit/ratelimit';

// update max allowed requests
defaultRateLimiter.setMaxRequests(10);

// update the timeout interval
defaultRateLimiter.setInterval(30000);

// update the storage implementation
defaultRateLimiter.setStorage(new RedisStorage());
Signature
function ratelimit(key: string): Promise<boolean>

Parameters

key

parameter
string