Skip to main content
Get up and running with Upstash Redis in under 5 minutes. This guide will walk you through creating a Redis database, installing the SDK, and executing your first commands.

Prerequisites

Before you begin, you’ll need:

Step 1: Create a Redis database

1

Sign up for Upstash

Go to console.upstash.com and create a free account.
2

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
3

Copy your credentials

After creation, you’ll see your database details. Copy:
  • UPSTASH_REDIS_REST_URL - Your database REST URL
  • UPSTASH_REDIS_REST_TOKEN - Your authentication token
Click the .env button in the console to copy both values in the correct format.

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
Never commit your .env file to version control. Add it to your .gitignore file.

Step 4: Write your first code

Create a new file index.ts (or index.js) and add:
index.ts

Step 5: Run your code

Execute your script:
You should see output similar to:
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

If you’re getting connection errors:
  1. Verify your credentials in the Upstash Console
  2. Check that your environment variables are loaded correctly
  3. Ensure your URL starts with https://
  4. Make sure your database region is accessible from your deployment region
For TypeScript errors:
  1. Ensure you have TypeScript 4.5 or higher
  2. Add "moduleResolution": "node" to your tsconfig.json
  3. Install the latest SDK version: npm install @upstash/redis@latest
If your data isn’t persisting:
  1. Check if you set an expiration time that’s too short
  2. Verify you’re not using a different database/environment
  3. Make sure you’re awaiting async operations

Get help

Need assistance? We’re here to help: