自动化与脚本
无 Upstash MCP 时在终端/CI 脚本中用…
当会话中没有 Upstash MCP 工具,需要在终端、shell 脚本或 CI 中以非交互 JSON 方式管理 Upstash 认证、Redis、团队、Vector、Search、QStash、Blob 等资源时使用。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 59/100 ×0.15
适用场景
无 Upstash MCP 时在终端/C特定
解决思路
- 运行 `upstash` CLI 管理 Upstash 服务;所有命令非交互,stdout 输出 JSON,错误输出到 stderr 为 `{ "error": "..." }`,退出码为 1。
- 安装 CLI:`npm i -g @upstash/cli`。
- 认证推荐:每台机器运行一次 `upstash login`,按提示输入 email 和 Developer API key(在 https://console.upstash.com/account/api 创建),验证后保存到 `~/.config/upstash/config.json`。
- 认证替代方式:导出环境变量 `UPSTASH_EMAIL=you@example.com` 和 `UPSTASH_API_KEY=your_api_key`;环境变量也会自动从 cwd 的 `.env` 加载。
- 认证替代方式:使用 `--email` / `--api-key` 内联传入;或使用 `--env-path <path>` 指向特定 `.env`。
- 认证优先级:flags > env vars > `.env` > 保存的 config;代理场景尽量使用 read-only API key,写操作会在 API 层失败,就像在 console 中一样。
- 资源 ID flags:`--db-id <id>` 用于 Redis,`--index-id <id>` 用于 Vector 和 Search,`--qstash-id <id>` 用于 QStash,`--bucket-id <id>` 用于 Blob,`--team-id <id>` 用于 Team。
- Redis 列出:`upstash redis list`。
- Redis 获取:`upstash redis get --db-id <id> [--hide-credentials]`。
- Redis 创建:`upstash redis create --name <name> --region <region> [--read-regions <r1> <r2>]`。
- Redis 删除:`upstash redis delete --db-id <id> [--dry-run]`。
- Redis 重命名:`upstash redis rename --db-id <id> --name <new-name>`。
- Redis 重置密码:`upstash redis reset-password --db-id <id>`。
- Redis 用量统计:`upstash redis stats --db-id <id>`。
- Redis 启用 TLS:`upstash redis enable-tls --db-id <id>`。
- Redis 启用/禁用逐出:`upstash redis {enable,disable}-eviction --db-id <id>`。
- Redis 启用/禁用自动升级:`upstash redis {enable,disable}-autoupgrade --db-id <id>`。
- Redis 变更计划:`upstash redis change-plan --db-id <id> --plan <free|payg|pro|paid>`。
- Redis 更新预算:`upstash redis update-budget --db-id <id> --budget <cents>`。
- Redis 更新区域:`upstash redis update-regions --db-id <id> --read-regions <r1> <r2>`。
- Redis 移动到团队:`upstash redis move-to-team --db-id <id> --team-id <id>`。
- Redis 区域(AWS):`us-east-1`、`us-east-2`、`us-west-1`、`us-west-2`、`ca-central-1`、`eu-central-1`、`eu-west-1`、`eu-west-2`、`sa-east-1`、`ap-south-1`、`ap-northeast-1`、`ap-southeast-1`、`ap-southeast-2`、`af-south-1`。
- Redis 区域(GCP):`us-central1`、`us-east4`、`europe-west1`、`asia-northeast1`。
- Redis 备份列出:`upstash redis backup list --db-id <id>`。
- Redis 备份创建:`upstash redis backup create --db-id <id> --name <name>`。
- Redis 备份删除:`upstash redis backup delete --db-id <id> --backup-id <id> [--dry-run]`。
- Redis 备份恢复:`upstash redis backup restore --db-id <id> --backup-id <id>`。
- Redis 启用/禁用每日备份:`upstash redis backup {enable,disable}-daily --db-id <id>`。
- Redis exec 使用 REST,而不是 Developer API key:`upstash redis exec --db-url <url> --db-token <token> SET key value`。
- Redis exec 使用 JSON 数组:`upstash redis exec --db-url <url> --db-token <token> --json '["SET","key","value"]'`。
- Redis exec 的 `--db-url` / `--db-token` 可回退到 `UPSTASH_REDIS_REST_URL` / `UPSTASH_REDIS_REST_TOKEN`;从 `upstash redis get --db-id <id>` 的 `endpoint` 和 `rest_token` 获取两者。
- Team 列出:`upstash team list`。
- Team 创建:`upstash team create --name <name> [--copy-cc]`。
- Team 删除:`upstash team delete --team-id <id> [--dry-run]`。
- Team 成员列出:`upstash team members --team-id <id>`。
- Team 添加成员:`upstash team add-member --team-id <id> --member-email <email> --role <admin|dev|finance>`。
- Team 移除成员:`upstash team remove-member --team-id <id> --member-email <email> [--dry-run]`。
- Vector 列出:`upstash vector list`。
- Vector 获取:`upstash vector get --index-id <id>`。
- Vector 创建:`upstash vector create --name <name> --region <region> --similarity-function <fn> --dimension-count <n> [--type payg] [--index-type <type>] [--embedding-model <m>] [--sparse-embedding-model <m>]`。
- Vector 删除:`upstash vector delete --index-id <id> [--dry-run]`。
- Vector 重命名:`upstash vector rename --index-id <id> --name <new-name>`。
- Vector 重置密码:`upstash vector reset-password --index-id <id>`。
- Vector 设置计划:`upstash vector set-plan --index-id <id> --plan <free|payg|fixed>`。
- Vector 转移:`upstash vector transfer --index-id <id> --target-account <id>`。
- Vector 聚合统计:`upstash vector stats`,聚合所有索引。
- Vector 索引统计:`upstash vector index-stats --index-id <id> [--period <1h|3h|12h|1d|3d|7d|30d>]`。
- Vector 区域:`eu-west-1`、`us-east-1`、`us-central1`。
- Vector 相似度:`COSINE`、`EUCLIDEAN`、`DOT_PRODUCT`。
- Vector 索引类型:`DENSE`、`SPARSE`、`HYBRID`。
- Vector dense 模型:`BGE_SMALL_EN_V1_5`、`BGE_BASE_EN_V1_5`、`BGE_LARGE_EN_V1_5`、`BGE_M3`。
- Vector sparse 模型:`BM25`、`BGE_M3`。
- Vector 使用 `HYBRID` 且托管嵌入时,设置 `--dimension-count 0`。
- Search 列出:`upstash search list`。
- Search 获取:`upstash search get --index-id <id>`。
- Search 创建:`upstash search create --name <name> --region <region> --type <free|payg|fixed>`。
- Search 删除:`upstash search delete --index-id <id> [--dry-run]`。
- Search 重命名:`upstash search rename --index-id <id> --name <new-name>`。
- Search 重置密码:`upstash search reset-password --index-id <id>`。
- Search 转移:`upstash search transfer --index-id <id> --target-account <id>`。
- Search 统计:`upstash search stats`。
- Search 索引统计:`upstash search index-stats --index-id <id> [--period <1h|3h|12h|1d|3d|7d|30d>]`。
- Search 区域:`eu-west-1`、`us-central1`。
- QStash 先运行列出,以映射 region → id:`upstash qstash list`。
- QStash 获取:`upstash qstash get --qstash-id <id>`。
- QStash 轮换 token:`upstash qstash rotate-token --qstash-id <id>`。
- QStash 设置计划:`upstash qstash set-plan --qstash-id <id> --plan <paid|qstash_fixed_1m|qstash_fixed_10m|qstash_fixed_100m>`。
- QStash 统计:`upstash qstash stats --qstash-id <id> [--period <1h|3h|12h|1d|3d|7d|30d>]`。
- QStash 获取 IPv4 CIDR 块用于 allowlisting:`upstash qstash ipv4`。
- QStash 移动到团队:`upstash qstash move-to-team --qstash-id <id> --target-team-id <id>`。
- QStash 更新预算:`upstash qstash update-budget --qstash-id <id> --budget <dollars>`,`0` 表示无限制。
- QStash 启用/禁用 prodpack:`upstash qstash {enable,disable}-prodpack --qstash-id <id>`。
- Blob 支持检查:运行 `upstash blob --help` 确认已安装 CLI 是否包含 Blob 支持;若命令不可用,则使用 console 管理 bucket,并在应用代码中使用 `upstash-blob-js`,直到 CLI 发布包含该功能。
- Blob 列出:`upstash blob list`。
- Blob 获取:`upstash blob get --bucket-id <id> [--hide-credentials]`。
- Blob 创建:`upstash blob create --name <name> [--visibility <private|public>] [--cors <origin> <origin>]`。
- Blob 删除:`upstash blob delete --bucket-id <id> [--dry-run]`。
- Blob credentials:`upstash blob credentials [--bucket-id <id>]`。
- Blob bucket 默认是 `private`;`blob get` 返回 bucket token,这是整个 bucket 的 bearer secret,仅需元数据时传 `--hide-credentials`。
- `blob credentials` 用 bucket token 换取临时、bucket-scoped 的 S3 凭证,用于 AWS CLI、rclone 或任何 S3 SDK;带 `--bucket-id` 时通过 Developer API 读取 token,不带 flag 时使用 `UPSTASH_BLOB_TOKEN` 且完全不需要账号认证。
- `expiresAt` 是 unix timestamp 秒数;与 `Date.now()` 比较前要乘以 1000,过期前重新 mint,不要缓存。
- Blob credentials 示例:`CREDS=$(upstash blob credentials --bucket-id <id>)`;`export AWS_ACCESS_KEY_ID=$(echo "$CREDS" | jq -r .accessKeyId)`;`export AWS_SECRET_ACCESS_KEY=$(echo "$CREDS" | jq -r .secretAccessKey)`;`export AWS_SESSION_TOKEN=$(echo "$CREDS" | jq -r .sessionToken)`。
- Blob credentials 上传示例:`aws s3 cp image.png "s3://$(echo "$CREDS" | jq -r .bucket)/image.png" --endpoint-url "$(echo "$CREDS" | jq -r .endpoint)" --region auto`。
- Blob 对象操作不是 CLI 命令;bucket 兼容 S3,因此用上述凭证配合 S3 工具,或应用代码使用 `upstash-blob-js` skill 的 TypeScript SDK。
- 约定:将任何输出 pipe 到 `jq` 提取字段,例如 `upstash redis list | jq '.[].database_id'`。
- 约定:任何 `delete` 或 `remove-member` 前先使用 `--dry-run`。
- 约定:当不需要 secret 时,在 `redis get` 和 `blob get` 上使用 `--hide-credentials`。
适用边界 · 注意事项
- 会话中已有 Upstash MCP 工具时不要使用此技能;直接调用 MCP,它们已覆盖创建、列出、重命名、删除 Redis 数据库,运行 Redis 命令,用量统计、备份、Vector/Search 索引、QStash 调度与消息、Blob 桶和 Box。安装 Upstash plugin 会注册托管服务器 `https://mcp.upstash.com/mcp`。
- 当已安装 CLI 不支持 `upstash blob` 子命令时,不要用它管理 Blob bucket;改用 console 管理 bucket,应用代码用 `upstash-blob-js`,直到 CLI 发布支持。
- 没有 Upstash 账号或 Developer API key、且无法创建时,无法进行需要账号认证的操作;只有使用 `UPSTASH_BLOB_TOKEN` 的无账号 Blob credentials 场景除外。