Installation
Quick Start
Import the SDK
The default export is optimized for Node.js:You can also use the explicit Node.js import:
Create a Redis instance
- From Environment
- With Credentials
Use This will read from:
fromEnv() to automatically load credentials from environment variables:UPSTASH_REDIS_REST_URLorKV_REST_API_URLUPSTASH_REDIS_REST_TOKENorKV_REST_API_TOKEN
The fallback variables (
KV_REST_API_URL and KV_REST_API_TOKEN) provide compatibility with Vercel KV and other platforms.Configuration Options
The Node.js SDK supports several configuration options:Connection Pooling with Agent
For optimal performance in Node.js applications with multiple sequential requests, use an HTTP(S) agent:Using fromEnv() with Options
You can combinefromEnv() with additional configuration:
Example Application
Platform Detection
The SDK automatically detects the runtime environment and sets appropriate telemetry:- Node.js: Reports as
node@<version>(e.g.,node@18.17.0) - Edge Runtime: Reports as
edge-lightwhen running in Vercel Edge Functions - Platform: Detects Vercel, AWS, or Upstash Console environments
Environment Variables
When usingRedis.fromEnv(), the SDK looks for these environment variables via process.env:
| Variable | Fallback | Description |
|---|---|---|
UPSTASH_REDIS_REST_URL | KV_REST_API_URL | Your Redis REST URL |
UPSTASH_REDIS_REST_TOKEN | KV_REST_API_TOKEN | Your Redis REST token |
UPSTASH_DISABLE_TELEMETRY | - | Set to disable telemetry |
If
process.env is not available (e.g., in Cloudflare Workers), use the platform-specific import instead: @upstash/redis/cloudflareRelated
- Vercel Guide - Using Redis with Vercel Functions
- Configuration - Complete configuration reference
- Examples - Node.js examples on GitHub