
Upstash Has Free Serverless Redis — Zero-Config Caching and Rate Limiting for Edge Functions
Why Upstash? Upstash is serverless Redis with per-request pricing. Pay $0 for idle time. Works with Vercel Edge, Cloudflare Workers, Deno Deploy — any edge runtime. npm install @upstash/redis import { Redis } from ' @upstash/redis ' const redis = Redis . fromEnv () // reads UPSTASH_REDIS_REST_URL + TOKEN await redis . set ( ' user:123 ' , { name : ' John ' , plan : ' pro ' }) const user = await redis . get ( ' user:123 ' ) Rate Limiting npm install @upstash/ratelimit import { Ratelimit } from ' @upstash/ratelimit ' import { Redis } from ' @upstash/redis ' const ratelimit = new Ratelimit ({ redis : Redis . fromEnv (), limiter : Ratelimit . slidingWindow ( 10 , ' 60 s ' ), // 10 requests per minute }) export async function middleware ( request ) { const ip = request . headers . get ( ' x-forwarded-for ' ) const { success } = await ratelimit . limit ( ip ) if ( ! success ) return new Response ( ' Rate limited ' , { status : 429 }) } QStash (Message Queue) import { Client } from ' @upstash
Continue reading on Dev.to Webdev
Opens in a new tab



