Created
April 22, 2026 22:46
-
-
Save basilleaf/39f1cac7d884116f276047dad481732c to your computer and use it in GitHub Desktop.
Add Upstash Rate Limiting to a Next js app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Go to upstash.com, create a free account, create a Redis database, and grab the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN from the dashboard. Add those to your .env. | |
| check Eviction Enable to evict entries when max data size is reached. ✅ | |
| install it: | |
| npm install @upstash/ratelimit @upstash/redis | |
| create the file: lib/ratelimit.ts | |
| ``` | |
| import { Ratelimit } from "@upstash/ratelimit"; | |
| import { Redis } from "@upstash/redis"; | |
| const RPM = 10 // 10 requests per minute | |
| export const ratelimit = new Ratelimit({ | |
| redis: Redis.fromEnv(), | |
| limiter: Ratelimit.slidingWindow(RPM, "1 m"), | |
| analytics: true, | |
| }); | |
| ``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment