Methods
This page contains information on what methods are available in Ratelimit and how they can be used. For information on the cost of these operations in term of number of Redis commands, refer to the Costs page.
limit
The limit
method is the heart of the Ratelimit algorithm.
It receives an identifier to rate limit. Additionally, it can be passed a req
parameter which can contain either a
geo
or a rate
field. geo
field is passed to the analytics but is not in use currenlty. The rate
field determines
the amount of tokens/requests to subtract from the state of the algorithm with regards to the provided identifier.
blockUntilReady
In case you don’t want to reject a request immediately but wait until it can be processed, we also provide
It is very similar to the limit
method and takes an identifier and returns the
same response. However if the current limit has already been exceeded, it will
automatically wait until the next window starts and will try again. Setting the
timeout parameter (in milliseconds) will cause the returned Promise to resolve
in a finite amount of time.
blockUntilReady
will not work as intended due to Date.now()
not behaving the same as in Node environments.For more information, check:
https://developers.cloudflare.com/workers/runtime-apis/web-standards
resetUsedTokens
This method resets the state of the algorithm with respect to some identifier:
getRemaining
This method returns the remaining tokens/requests available for some identifier:
Was this page helpful?