@upstash/ratelimit
:
ratelimit.limit(identifier)
method. If the success
field is true, we allow the expensive calculation to go through.
For more examples, see the Examples.
UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
environment variables must be set in order for the Redis.fromEnv()
command to work. You can get the values of these environment variables from the Upstash Console by navigating to the page of the Redis instance you created.
An alternative of using the Redis.fromEnv()
method is to pass the variables yourself. This can be useful if you save these environment variables with a different name:
UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
environment variables and their values.limit
method. There are other methods we can use in the Ratelimit. These are:
blockUntilReady
: Process a request only when the rate-limiting algorithm allows it.resetUsedTokens
: Reset the rate limiter state for some identifier.getRemaining
: Get the remaining tokens/requests left for some identifier.