upstash-redis
Use to add serverless Redis (caching, counters, sessions) or rate limiting over HTTP from edge/serverless runtimes.
Tech stack
Works with
---
name: upstash-redis
description: Use to add serverless Redis (caching, counters, sessions) or rate limiting over HTTP from edge/serverless runtimes.
license: MIT
---
# Upstash Redis — Skillship
> Serverless, HTTP-based Redis that works from edge/serverless runtimes (Vercel, Cloudflare Workers,
> Lambda) where raw TCP is restricted. Pay-per-request, scales to zero.
## 🧭 When to use this skill
- Use when: you need caching, counters, sessions, queues, or rate limiting in serverless/edge code.
- Use when: your runtime can't open TCP sockets (edge) — Upstash speaks HTTP/REST.
- Don't use for: relational data or transactions across tables (use Postgres).
## ⚡ Quickstart
### 1. Install
```bash
npm install @upstash/redis
# For rate limiting:
npm install @upstash/ratelimit
```
### 2. Configure env (Console → your DB → REST API)
```bash
UPSTASH_REDIS_REST_URL=https://<id>.upstash.io
UPSTASH_REDIS_REST_TOKEN=<token>
```
### 3. Minimal working example
```ts
import { Redis } from "@upstash/redis";
const redis = Redis.fromEnv(); // reads UPSTASH_REDIS_REST_URL/_TOKEN
await redis.set("counter", 0);
await redis.incr("counter");
const value = await redis.get<number>("counter");
```
## 🧩 Common recipes
### Recipe: Cache with TTL
```ts
await redis.set("user:42", JSON.stringify(user), { ex: 60 }); // expires in 60s
const cached = await redis.get<string>("user:42");
```
### Recipe: Data structures
```ts
await redis.zadd("scores", { score: 1, member: "team1" }); // sorted set
await redis.lpush("queue", "job-1"); // list
await redis.hset("people", { name: "joe" }); // hash
await redis.sadd("animals", "cat"); // set
```
### Recipe: Rate limiting (sliding window)
```ts
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.slidingWindow(10, "10 s"), // 10 requests / 10s
analytics: true,
});
const identifier = userId ?? ip; // per-user or per-IP
const { success } = await ratelimit.limit(identifier);
if (!success) return new Response("Too many requests", { status: 429 });
```
### Recipe: Edge runtimes (Cloudflare Workers / Vercel Edge)
```ts
import { Redis } from "@upstash/redis/cloudflare"; // edge-safe import
// Ensure background analytics/replication finish before the runtime exits:
const { success, pending } = await ratelimit.limit("id");
context.waitUntil(pending); // Workers; on Vercel use waitUntil from the Functions API
```
## 🚀 Ship to production
- [ ] `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` set in the host env (Vercel/Workers secrets).
- [ ] Rate-limit background work awaited via `waitUntil(pending)` in edge/serverless.
- [ ] Choose a primary region near your writes; add read regions for global reads.
- [ ] Set TTLs on cache keys so memory/cost don't grow unbounded.
- [ ] Namespace keys (e.g. `prefix`) if sharing a DB across apps to avoid collisions.
## 🔐 Security & secrets
- The REST token grants full DB access — store as a secret, never ship to the browser bundle.
- For client-side reads, create a **read-only** token; never expose the read/write token publicly.
## 🐛 Common errors & fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| `fromEnv()` throws about missing env | Env vars not set / wrong names | Set `UPSTASH_REDIS_REST_URL` and `_TOKEN` exactly |
| Rate-limit counts/analytics missing on edge | Runtime exited before background ops | `context.waitUntil(pending)` |
| Values come back as strings, not objects | Redis stores strings | `JSON.stringify` on write, parse on read (or use typed `get<T>`) |
| Higher-than-expected cost | No TTLs / chatty polling | Add TTLs, cache aggressively, batch commands |
## 💰 Pricing gotchas
- Billed per request (command). MultiRegion replication and analytics add background commands per `limit()` call.
## 📚 Sources
- https://upstash.com/docs/redis/overall/getstarted
- https://upstash.com/docs/redis/sdks/ts/getstarted
- https://upstash.com/docs/redis/sdks/ratelimit-ts/gettingstartedMore API Design skills
lark-event
larksuite/cli
Lark/Feishu real-time event listening / subscribing / consuming: stream events as NDJSON via `lark-cli event consume <EventKey>` (covers IM messages/reactions/chat changes, Approval status changes, Task updates, VC meeting started/joined/ended, Minutes generated, Whiteboard updated, etc.). Use for Lark bots, real-time message processing, long-running subscribers, streaming webhook/push handlers. Supports `--max-events` / `--timeout` bounded runs and a stderr ready-marker contract — designed for AI agents running as subprocesses.
lark-contact
larksuite/cli
飞书 / Lark 通讯录:按姓名 / 邮箱解析成 open_id,或按 open_id 反查姓名 / 部门 / 邮箱 / 联系方式 / 个人状态 / 签名,以及按关键词搜索当前用户可见的机器人 / 智能体(agent)。当用户提到一个名字要下一步发消息 / 排日程,或拿到 open_id 想查具体信息时使用。不负责部门树遍历、按部门列员工、组织架构图,这类需求走原生 OpenAPI。
lark-openapi-explorer
larksuite/cli
飞书/Lark 原生 OpenAPI 探索:从官方文档库中挖掘未经 CLI 封装的原生 OpenAPI 接口。当用户的需求无法被现有 lark-* skill 或 lark-cli 已注册命令满足,需要查找并调用原生飞书 OpenAPI 时使用。

