Installation
Quick Start
Choosing the Right Import
The Upstash Redis SDK automatically works with both Node.js and Edge runtimes:- Vercel Functions (Node.js runtime)
- Vercel Edge Functions (Edge runtime)
- The SDK automatically detects the runtime and adjusts accordingly
You don’t need different imports for different runtimes when using Vercel. The default import handles both!
Configuration
Using fromEnv() (Recommended)
The easiest way to configure Redis is usingfromEnv(), which automatically reads from environment variables:
UPSTASH_REDIS_REST_URLorKV_REST_API_URLUPSTASH_REDIS_REST_TOKENorKV_REST_API_TOKEN
Using Vercel KV Integration
If you’re using the Vercel KV integration, the environment variables are automatically set as:KV_REST_API_URLKV_REST_API_TOKEN
Redis.fromEnv() works out of the box!
Manual Configuration
With Options
Environment Variables
1
Add environment variables to your Vercel project
- Go to your project settings in Vercel
- Navigate to Environment Variables
- Add:
UPSTASH_REDIS_REST_URL: Your Redis REST URLUPSTASH_REDIS_REST_TOKEN: Your Redis REST token
2
Or use .env.local for local development
3
Or use the Vercel KV Integration
The Vercel KV integration automatically sets up the required environment variables.
Configuration Options
Node.js Runtime (Vercel Functions)
Edge Runtime (Vercel Edge Functions)
Complete Examples
Next.js App Router with Edge Runtime
Next.js App Router with Node.js Runtime
Next.js Pages Router
Runtime Detection
The SDK automatically detects the Vercel runtime:- Edge Runtime: Reports as
edge-lightin telemetry - Node.js Runtime: Reports as
node@<version>in telemetry - Platform: Automatically detected as
vercel
Performance Tips
1. Enable Keep-Alive
2. Use Edge Runtime for Global Performance
Edge Functions run closer to your users:3. Enable Auto-Pipelining
Troubleshooting
”Unable to find environment variable”
Make sure environment variables are set in your Vercel project settings or.env.local file.
Edge Runtime Errors
If using theagent option, remove it for Edge Runtime:
Related
- Vercel App Router Example - Complete example
- Vercel Pages Router Example - Complete example
- Vercel KV Documentation - Official Vercel KV docs
- Configuration - Complete configuration reference