How to Get Started with Upstash Redis

5 min read

TL;DR: Sign up at upstash.com, create a free Redis database (256 MB, 500K commands/month), grab your REST URL and token, then use the TypeScript SDK or REST API to start caching, rate limiting, or managing sessions in under 5 minutes. No infrastructure setup required.

Key Takeaways

  • Free tier supports up to 256 MB storage and 500K commands per month, no credit card required.
  • Upstash Redis is HTTP/REST-based, making it native to serverless (Vercel, Cloudflare Workers, AWS Lambda).
  • The @upstash/redis SDK handles authentication and command serialization automatically.
  • Upstash charges $0.2 per 100K commands on pay-as-you-go; fixed plans start at $10/month.
  • Database is live and queryable within seconds of creation; no waiting for infrastructure provisioning.

Sign Up and Create Your Database

Let's head to console.upstash.com and click Sign Up. We can use email, GitHub, or Google to register. Once logged in, we'll click + Create Database in the top right.

A dialog appears asking for a database name, primary region (closest to our writes), and read region (closest to our reads). Let's select a region near our users for lowest latency. The free tier is available globally; we pick one primary region.

Let's click Next and select the Free plan. Our database is running within seconds. We land on a dashboard showing our database endpoint, password, and monthly command usage.

Grab Your Credentials

On the database detail page, we'll see two credentials under the "REST API" tab:

  • UPSTASH_REDIS_REST_URL — Something like https://[name].upstash.io
  • UPSTASH_REDIS_REST_TOKEN — A long alphanumeric string

Let's copy both. These are what authenticate our API requests. Let's treat the token like an API key: don't commit it to version control, let's use environment variables instead.

Option 1: Connect with the TypeScript SDK

The @upstash/redis SDK is the easiest way to work with Upstash in Node.js, Vercel, or Cloudflare Workers.

Let's install it:

npm install @upstash/redis

Let's create a connection:

import { Redis } from "@upstash/redis";

const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL,
  token: process.env.UPSTASH_REDIS_REST_TOKEN,
});

// Set a key
await redis.set("greeting", "hello world");

// Get a key
const value = await redis.get("greeting");
console.log(value); // "hello world"

The SDK includes TypeScript types, so you get autocomplete and type safety automatically. No connection pooling to manage: each redis.* call fires an HTTP request to Upstash.

Option 2: Use the REST API Directly

If we prefer raw HTTP, Upstash's REST API maps Redis commands to POST endpoints:

curl -X POST "https://[name].upstash.io/set/mykey/myvalue" \
  -H "Authorization: Bearer $UPSTASH_REDIS_REST_TOKEN"

For example, to increment a counter:

curl -X POST "https://[name].upstash.io/incr/page_views" \
  -H "Authorization: Bearer $UPSTASH_REDIS_REST_TOKEN"

This is useful for edge runtimes (Cloudflare Workers, Fastly Compute) or languages without a first-class SDK. The response is JSON.

Common Patterns: Caching, Rate Limiting, Counters

Let's walk through some practical examples using the TypeScript SDK.

Cache API responses:

const cacheKey = `user:${userId}:profile`;
let user = await redis.get(cacheKey);

if (!user) {
  user = await fetchUserFromDB(userId);
  // Cache for 1 hour
  await redis.set(cacheKey, JSON.stringify(user), { ex: 3600 });
}

return JSON.parse(user);

Rate limiting with sorted sets:

const key = `rate:${ip}`;
const now = Date.now();
const window = now - 60000; // Last 60 seconds

// Add current request
await redis.zadd(key, { score: now, member: `${now}:${Math.random()}` });

// Count requests in window
const count = await redis.zcount(key, window, now);

if (count > 100) {
  return { status: 429, message: "Too many requests" };
}

// Clean up old entries
await redis.zremrangebyscore(key, "-inf", window);

Increment counters:

await redis.incr("daily_signups");
const total = await redis.get("daily_signups");
console.log(`${total} new users today`);

Monitoring and Costs

Your Upstash console shows real-time metrics: command count, data size, bandwidth, and response times. The free tier refreshes every 10 seconds.

On pay-as-you-go, you're charged per command. A simple set or get is one command. Pipelined commands (multiple operations in one request) count individually. The first 500K commands per month stay free; after that, it's $0.2 per 100K commands.

For consistent, heavy usage (10K+ commands/day), a fixed plan is cheaper. The $10/month plan handles most applications.

Comparison: When to Use Upstash vs. Other Options

AspectUpstashRedis CloudAWS ElastiCache
ConnectionHTTP/REST (serverless-native)TCP (connection pooling)VPC only (not serverless)
Free tier256 MB, 500K commands/month30 MB freeNo free tier
Pricing$0.2/100K commands or fixed plans$0.15/100K or fixedPer-instance + data transfer
Setup30 seconds2 minutes5+ minutes (VPC setup)
LatencyUltra-low globally (multi-region)Good, regionalVariable (depends on VPC)
Best forServerless, edge, hobby projectsProduction TCP appsEnterprise VPC deployments

Choose Upstash if you're on Vercel, Cloudflare Workers, or building a serverless app where you don't have persistent TCP connections. Choose Redis Cloud if you need traditional TCP pooling. Choose ElastiCache only if you're running inside AWS and need VPC isolation.

FAQ

Do I need to manage connections? No. Every request is stateless HTTP. Upstash handles pooling on their side.

Can I use Upstash with any Redis client? Most clients expect TCP. Use the @upstash/redis SDK or raw REST API calls. For traditional clients (redis-py, redis-go), you'd need a TCP bridge.

What happens when I hit the free tier limit? Your commands will fail until the next billing cycle (or you upgrade). Upstash doesn't automatically charge or shut you down; you have to manually upgrade to pay-as-you-go.

How long does a database live? Indefinitely, as long as you have an active account. Upstash doesn't delete inactive databases.

Can I replicate across regions? Global replication (read replicas) is available on paid plans. The free tier is single-region.

What data structures does Upstash support? All standard Redis types: strings, lists, sets, sorted sets, hashes, and streams. Redis Search is available as a separate product.

Is my data encrypted? At rest: encryption is available on fixed and enterprise plans. In transit: TLS is always on. Free tier stores data encrypted on disk but doesn't highlight it.

Can I migrate from Redis Cloud or AWS? Yes. Use redis-migrate or a script to dump and restore. Upstash is fully Redis-compatible.

How do I delete my database? Go to the database settings and click Delete Database. Data is gone immediately.