upstash-redis
できること
Upstash Redisを使って、直接の接続をサポートしていない環境でも、アプリケーションがデータを素早く保存・取得できるようにします。重要な情報を入れておく、高速な「金庫」のようなものです。
使う場面
- ✓一時的な情報(キャッシュ)を保存したいとき。
- ✓Webサイトでユーザーのセッションを管理するとき。
- ✓訪問数やクリック数などのイベントを数えたいとき。
スキルのリンク
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/upstash-redis/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“ユーザー名「Maria」をID「user:123」で保存し、1時間後に期限切れになるように設定してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
アプリケーションはインターネット経由のリクエストで、データをUpstash Redisに送信します。Upstash Redisはそのデータを保存し、アプリケーションが要求したときに返します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Upstash Redis
Overview
@upstash/redis is a Redis client that talks to an Upstash Redis database over
HTTPS instead of a TCP connection. Because every command is a stateless HTTP
request, it works in environments where a pooled TCP client is awkward or
impossible: Vercel and Netlify functions, Cloudflare Workers, Deno, Bun, and
Next.js middleware. The client serializes and deserializes JavaScript values
automatically, so numbers and objects round-trip without manual JSON.parse.
When to Use This Skill
- Use when the user needs a cache, session store, counter, leaderboard, or simple queue from a serverless or edge function.
- Use when the user mentions Upstash Redis,
UPSTASH_REDIS_REST_URL, or@upstash/redis. - Use when migrating an
ioredisornode-rediscall site to a runtime that cannot hold a persistent TCP socket. - Do not use for a self-hosted or non-Upstash Redis server; the client only
speaks the Upstash REST protocol. Use
ioredisornode-redisthere. - Do not use for Redis administration or CLI work; see
redis-cli.
How It Works
Step 1: Configure credentials
Create a database in the Upstash console and copy the REST URL and token into environment variables. Never hardcode them.
UPSTASH_REDIS_REST_URL=https://<your-db>.upstash.io
UPSTASH_REDIS_REST_TOKEN=<your-rest-token>
Step 2: Create one client per module
import { Redis } from "@upstash/redis";
export const redis = Redis.fromEnv();
On Cloudflare Workers, import from @upstash/redis/cloudflare and pass the
worker env object: Redis.fromEnv(env).
Step 3: Call Redis commands as methods
Command names are lowercase methods (get, set, hset, zadd, incr).
Values are auto-serialized; pass and receive native JavaScript types.
Examples
Example 1: Cache-aside with a TTL
import { Redis } from "@upstash/redis";
const redis = Redis.fromEnv();
export async function getUser(id: string) {
const cached = await redis.get<{ id: string; name: string }>(`user:${id}`);
if (cached) return cached;
const user = await db.users.findById(id);
await redis.set(`user:${id}`, user, { ex: 3600 }); // expires in 1 hour
return user;
}
export async function invalidateUser(id: string) {
await redis.del(`user:${id}`);
}
Example 2: Batch commands in a pipeline
const pipeline = redis.pipeline();
pipeline.hset("user:1", { name: "Alice", plan: "pro" });
pipeline.incr("signups:total");
pipeline.zadd("leaderboard", { score: 120, member: "user:1" });
const [hsetResult, signups, zaddResult] = await pipeline.exec();
pipeline() batches independent commands into one round trip. It is not
atomic; use redis.multi() for MULTI/EXEC or a reviewed server-side Lua script
when commands must run as one unit.
Best Practices
- ✅ Read credentials with
Redis.fromEnv()or from a secrets manager. - ✅ Set a TTL (
{ ex: seconds }) on cache entries so stale data expires. - ✅ Namespace keys (
user:123,session:abc) to keep the keyspace readable. - ✅ Use
pipeline()ormget/msetinstead of many sequential awaits. - ❌ Don't
JSON.stringifyvalues beforeset; the client already does it. - ❌ Don't call
keys("*")in request handlers; usescanfor large keyspaces. - ❌ Don't store secrets or PII in Redis without a retention plan and TTL.
Limitations
- Requires an Upstash Redis database; it cannot connect to other Redis servers.
- Each command is an HTTP request, so latency is higher than a warm TCP connection; batch with pipelines where it matters.
- Transactions (
multi()) do not roll back on runtime errors, andWATCHis not available over REST; use a Lua script for atomic check-and-set. - Pub/Sub subscribe and blocking commands (
BLPOP,XREAD BLOCK) are not supported over the REST client. - This skill covers the TypeScript client only. Python, Go, and other SDKs differ in method names.
- This skill does not replace environment-specific validation, testing, or expert review.
Security & Safety Notes
- The REST token grants full read/write access to the database. Keep it in server-side environment variables; never ship it to a browser bundle.
- Use a read-only token from the console for read-only workloads.
- Commands such as
flushdbanddelare destructive; confirm with the user before running them against a production database.
Common Pitfalls
…
よくある質問
通常のデータベースではなくUpstash Redisを使う理由は何ですか?
非常に高速に動作するように最適化されており、長時間つながり続ける接続を扱うのが苦手なサーバーレスやエッジといった、現代的な実行環境とよく合います。
「キー」と「バリュー」とは何ですか?
「キー」はファイル名、「バリュー」はそのファイルの中身のようなものだと考えてください。キーを使って値を探し、取り出します。
どんな種類の情報でも保存できますか?
はい、テキストや数値に加えて、オブジェクトのような複雑なデータ構造も保存できます。変換はシステムが自動で行います。
詳細
作者による元の説明
Use the @upstash/redis HTTP client for caching, sessions, counters, and Redis data structures from serverless and edge runtimes without connection pooling.
人気
- GitHubのスター
- 48k
- ランキング
- #6072
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
00-andruia-consultant
48kエージェントがAIプロジェクトの立ち上げや改善を支援します。コードを分析し、ツールを提案し、スペイン語で行動計画を作成します。
007
48kエージェントがセキュリティ監査と脅威モデリングを行えるようにします。攻撃や脆弱性からプロジェクトを守るのに役立ちます。
10-andruia-skill-smith
48kエージェントがAIツールの作成や改善を支援します。ツールの動作を定義し、ドキュメントを書き、構造を検証します。
20-andruia-niche-intelligence
48kエージェントが特定の業界に関する要約を作成できるようにします。信頼できる情報源を使って、プロジェクトの背景、ルール、利用パターン、リスクを把握するのに役立ちます。
似ているスキル
discrawl
394k保存済みのローカルなDiscordメッセージのアーカイブを検索して要約し、その新しさを確認し、ダイレクトメッセージを読めるようエージェントを支援します。
clickhouse-io
280kエージェントがClickHouseデータベースのクエリとスキーマを最適化できるようにします。高性能な分析処理向けのベストプラクティスを適用します。分析クエリが遅すぎるときに使います。
scientific-db-pubmed-database
280kエージェントが生物医学分野の科学論文を検索するのに役立ちます。特定の医療情報が必要な研究に便利です。