Redis Over HTTP
Upstash gives you serverless Redis accessible via simple HTTP requests. No connection management, no drivers needed. Free tier: 10K commands/day.
HTTP API (No SDK Needed)
curl https://your-endpoint.upstash.io/set/mykey/myvalue \
-H "Authorization: Bearer your_token"
curl https://your-endpoint.upstash.io/get/mykey \
-H "Authorization: Bearer your_token"
Python
import requests
URL = "https://your-endpoint.upstash.io"
TOKEN = "your_token"
HEADERS = {"Authorization": f"Bearer {TOKEN}"}
def redis_set(key, value, ex=None):
cmd = f"/set/{key}/{value}"
if ex: cmd += f"/ex/{ex}"
return requests.get(f"{URL}{cmd}", headers=HEADERS).json()
def redis_get(key):
return requests.get(f"{URL}/get/{key}", headers=HEADERS).json()["result"]
def redis_incr(key):
return requests.get(f"{URL}/incr/{key}", headers=HEADERS).json()["result"]
# Usage
redis_set("visits", 0)
redis_incr("visits")
print(f"Visits: {redis_get(visits)}")
JavaScript
import { Redis } from "@upstash/redis";
const redis = new Redis({ url: "https://your-endpoint.upstash.io", token: "your_token" });
await redis.set("user:1", { name: "John", role: "admin" });
const user = await redis.get("user:1");
console.log(user); // { name: "John", role: "admin" }
Real Use Cases
- Rate limiting — count requests per IP per minute
- Session storage — store user sessions in Redis
- Caching — cache expensive API responses
- Leaderboards — sorted sets for rankings
- Pub/Sub — real-time notifications
Rate Limiter in 5 Lines
def is_rate_limited(ip, limit=100, window=60):
key = f"rate:{ip}"
count = redis_incr(key)
if count == 1:
requests.get(f"{URL}/expire/{key}/{window}", headers=HEADERS)
return int(count) > limit
Free Tier
- 10K commands/day
- 256MB storage
- 1 database
- Global replication
More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
Top comments (0)