# SET a key
-weight: 500;">curl "https://YOUR_ENDPOINT.upstash.io/set/user:1/alex" \ -H "Authorization: Bearer YOUR_TOKEN" # GET a key
-weight: 500;">curl "https://YOUR_ENDPOINT.upstash.io/get/user:1" \ -H "Authorization: Bearer YOUR_TOKEN"
# SET a key
-weight: 500;">curl "https://YOUR_ENDPOINT.upstash.io/set/user:1/alex" \ -H "Authorization: Bearer YOUR_TOKEN" # GET a key
-weight: 500;">curl "https://YOUR_ENDPOINT.upstash.io/get/user:1" \ -H "Authorization: Bearer YOUR_TOKEN"
# SET a key
-weight: 500;">curl "https://YOUR_ENDPOINT.upstash.io/set/user:1/alex" \ -H "Authorization: Bearer YOUR_TOKEN" # GET a key
-weight: 500;">curl "https://YOUR_ENDPOINT.upstash.io/get/user:1" \ -H "Authorization: Bearer YOUR_TOKEN"
-weight: 500;">npm -weight: 500;">install @upstash/redis
-weight: 500;">npm -weight: 500;">install @upstash/redis
-weight: 500;">npm -weight: 500;">install @upstash/redis
import { Redis } from "@upstash/redis"; const redis = new Redis({ url: "https://YOUR_ENDPOINT.upstash.io", token: "YOUR_TOKEN",
}); // Basic operations
await redis.set("session:abc", { userId: 1, role: "admin" }, { ex: 3600 });
const session = await redis.get("session:abc"); // Rate limiting
const key = `ratelimit:${userId}`;
const count = await redis.incr(key);
if (count === 1) await redis.expire(key, 60);
if (count > 100) throw new Error("Rate limited"); // Sorted set for leaderboard
await redis.zadd("leaderboard", { score: 1500, member: "player1" });
const top10 = await redis.zrange("leaderboard", 0, 9, { rev: true });
import { Redis } from "@upstash/redis"; const redis = new Redis({ url: "https://YOUR_ENDPOINT.upstash.io", token: "YOUR_TOKEN",
}); // Basic operations
await redis.set("session:abc", { userId: 1, role: "admin" }, { ex: 3600 });
const session = await redis.get("session:abc"); // Rate limiting
const key = `ratelimit:${userId}`;
const count = await redis.incr(key);
if (count === 1) await redis.expire(key, 60);
if (count > 100) throw new Error("Rate limited"); // Sorted set for leaderboard
await redis.zadd("leaderboard", { score: 1500, member: "player1" });
const top10 = await redis.zrange("leaderboard", 0, 9, { rev: true });
import { Redis } from "@upstash/redis"; const redis = new Redis({ url: "https://YOUR_ENDPOINT.upstash.io", token: "YOUR_TOKEN",
}); // Basic operations
await redis.set("session:abc", { userId: 1, role: "admin" }, { ex: 3600 });
const session = await redis.get("session:abc"); // Rate limiting
const key = `ratelimit:${userId}`;
const count = await redis.incr(key);
if (count === 1) await redis.expire(key, 60);
if (count > 100) throw new Error("Rate limited"); // Sorted set for leaderboard
await redis.zadd("leaderboard", { score: 1500, member: "player1" });
const top10 = await redis.zrange("leaderboard", 0, 9, { rev: true });
from upstash_redis import Redis redis = Redis(url="https://YOUR_ENDPOINT.upstash.io", token="YOUR_TOKEN") redis.set("key", "value", ex=3600)
value = redis.get("key") # Hash
redis.hset("user:1", {"name": "Alex", "email": "[email protected]"})
user = redis.hgetall("user:1")
from upstash_redis import Redis redis = Redis(url="https://YOUR_ENDPOINT.upstash.io", token="YOUR_TOKEN") redis.set("key", "value", ex=3600)
value = redis.get("key") # Hash
redis.hset("user:1", {"name": "Alex", "email": "[email protected]"})
user = redis.hgetall("user:1")
from upstash_redis import Redis redis = Redis(url="https://YOUR_ENDPOINT.upstash.io", token="YOUR_TOKEN") redis.set("key", "value", ex=3600)
value = redis.get("key") # Hash
redis.hset("user:1", {"name": "Alex", "email": "[email protected]"})
user = redis.hgetall("user:1")
// Vercel Edge Function / Cloudflare Worker
export default async function handler(req) { const redis = new Redis({ url: process.env.UPSTASH_REDIS_REST_URL, token: process.env.UPSTASH_REDIS_REST_TOKEN, }); const visits = await redis.incr("page:visits"); return new Response(`Visits: ${visits}`);
}
// Vercel Edge Function / Cloudflare Worker
export default async function handler(req) { const redis = new Redis({ url: process.env.UPSTASH_REDIS_REST_URL, token: process.env.UPSTASH_REDIS_REST_TOKEN, }); const visits = await redis.incr("page:visits"); return new Response(`Visits: ${visits}`);
}
// Vercel Edge Function / Cloudflare Worker
export default async function handler(req) { const redis = new Redis({ url: process.env.UPSTASH_REDIS_REST_URL, token: process.env.UPSTASH_REDIS_REST_TOKEN, }); const visits = await redis.incr("page:visits"); return new Response(`Visits: ${visits}`);
} - 10,000 commands/day — reads and writes combined
- 256 MB storage — enough for sessions, cache, rate limiting
- REST API — HTTP-based, works from edge/serverless (no TCP needed)
- Global replication — read replicas in multiple regions
- Durable storage — data persists (not just in-memory)
- TLS encryption — secure by default
- QStash — free message queue (500 messages/day) - 30+ Free APIs Every Developer Should Bookmark
- Resend Has a Free API
- Algolia Has a Free Tier
- MongoDB Atlas Has a Free Tier
- Auth0 Has a Free Tier
- Cloudinary Has a Free API
- Firebase Has a Free Tier
- Supabase Has a Free Tier
- Stripe Has a Free API
- GitHub Has a Free API
- Notion Has a Free API
- PlanetScale Has a Free API
- Neon Has a Free API