Installation
Quick Start
1
Import from the Cloudflare-specific path
Always use
@upstash/redis/cloudflare when deploying to Cloudflare Workers. The default import is optimized for Node.js and may not work correctly.2
Define your environment interface
3
Use Redis in your worker
- Module Worker (Recommended)
- Service Worker
- With Direct Credentials
Configuration Options
Using fromEnv() with Options
Environment Variables
1
Add secrets using Wrangler CLI
2
Or configure in wrangler.toml (for development)
Environment Binding
Cloudflare Workers can bind environment variables in two ways:1. Module Workers (Recommended)
Pass theenv object to Redis.fromEnv():
2. Global Variables
If you don’t pass theenv object, the SDK will attempt to read from global variables:
Module workers with explicit
env passing is the recommended approach for better type safety and clarity.Complete Example
Telemetry
The SDK automatically reports"cloudflare" as the platform in telemetry data. To disable telemetry:
UPSTASH_DISABLE_TELEMETRY environment variable in your env object.
Related
- Cloudflare Workers Example - Complete example on GitHub
- Cloudflare Workers TypeScript Example - TypeScript example
- Configuration - Complete configuration reference