Prerequisites
Before you begin, you’ll need:- A free Upstash account
- Node.js 14 or higher (or Bun/Deno)
- A code editor
Step 1: Create a Redis database
Sign up for Upstash
Go to console.upstash.com and create a free account.
Create a new database
Click Create Database in the Upstash Console.
- Choose a name for your database
- Select a region close to your users
- Click Create
Step 2: Install the SDK
Install the Upstash Redis SDK using your preferred package manager:Step 3: Set up environment variables
Create a.env file in your project root and add your credentials:
.env
Step 4: Write your first code
Create a new fileindex.ts (or index.js) and add:
index.ts
Step 5: Run your code
Execute your script:Congratulations! You’ve successfully connected to Upstash Redis and executed your first commands.
Common patterns
TypeScript support
The SDK is fully typed. Use generics for type safety:Working with JSON
Use the built-in JSON support for complex objects:Batch operations with pipelines
Execute multiple commands efficiently:Auto-pipelining
Enable auto-pipelining for automatic batching:Platform-specific setup
Cloudflare Workers
Vercel Edge Functions
Next.js App Router
app/api/data/route.ts
What’s next?
Core Concepts
Learn about client configuration, pipelines, and advanced features
API Reference
Explore all available Redis commands and methods
Platform Guides
Platform-specific setup for Cloudflare, Vercel, AWS, and more
Examples
See real-world examples and best practices
Troubleshooting
Connection errors
Connection errors
If you’re getting connection errors:
- Verify your credentials in the Upstash Console
- Check that your environment variables are loaded correctly
- Ensure your URL starts with
https:// - Make sure your database region is accessible from your deployment region
TypeScript errors
TypeScript errors
For TypeScript errors:
- Ensure you have TypeScript 4.5 or higher
- Add
"moduleResolution": "node"to yourtsconfig.json - Install the latest SDK version:
npm install @upstash/redis@latest
Data not persisting
Data not persisting
If your data isn’t persisting:
- Check if you set an expiration time that’s too short
- Verify you’re not using a different database/environment
- Make sure you’re awaiting async operations
Get help
Need assistance? We’re here to help:- Join our Discord community
- Check the GitHub repository
- Read the full documentation
- Contact Upstash support