Install the Upstash Redis SDK for your platform using your preferred package manager.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/upstash/redis-js/llms.txt
Use this file to discover all available pages before exploring further.
Package managers
- npm
- yarn
- pnpm
- bun
Platform-specific imports
The SDK provides optimized entry points for different platforms. Choose the right import for your environment.Node.js
The default export is optimized for Node.js:Supports Node.js 14 and above. The SDK automatically detects your Node.js version and adjusts accordingly.
Cloudflare Workers
Use the Cloudflare-specific import for Workers:The Cloudflare import is optimized for Workers and removes Node.js-specific code for smaller bundle sizes.
Fastly Compute@Edge
Use the Fastly-specific import:Deno
Import directly from esm.sh:Environment variables
The SDK automatically reads credentials from environment variables when usingRedis.fromEnv().
Standard environment variables
Set these variables in your.env file:
.env
Vercel KV compatibility
The SDK also supports Vercel KV environment variable names:.env
If both sets of variables are present,
UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN take precedence.Using fromEnv()
Configuration options
When creating a Redis client, you can configure various options:Example with options
TypeScript configuration
The SDK is written in TypeScript and includes type definitions. No additional@types package is needed.
If you’re using TypeScript, ensure your tsconfig.json includes:
tsconfig.json
CommonJS vs ES Modules
The SDK supports both CommonJS and ES Modules:Bundler configuration
The SDK works with all major bundlers without additional configuration.Webpack
No configuration needed. The SDK uses standard exports that Webpack handles automatically.Vite
No configuration needed. Vite will tree-shake unused code automatically.esbuild
No configuration needed. The SDK includes proper exports for esbuild.Rollup
No configuration needed. The SDK is compatible with Rollup’s ES module handling.Disabling telemetry
The SDK sends anonymous telemetry data by default. To disable it:Via environment variable
.env
Via configuration
Telemetry helps improve the SDK by collecting:
- SDK version
- Platform (Cloudflare, Vercel, AWS, etc.)
- Runtime version (e.g., node@18.x)
Verify installation
Test your installation with this simple script:test.ts
Ping result: PONG, your installation is successful!
Troubleshooting
Module not found error
Module not found error
Make sure you’ve installed the package:If using Cloudflare or Fastly, use the correct import:
Environment variables not found
Environment variables not found
Ensure your
.env file is in the project root and you’re loading it correctly:TypeScript errors
TypeScript errors
Make sure you’re using TypeScript 4.5 or higher:Update your
tsconfig.json:Cloudflare Workers compatibility
Cloudflare Workers compatibility
Use the Cloudflare-specific import and ensure you’re passing the
env object:Next steps
Quick start
Create your first Redis client
API reference
Explore all available commands