Upstash 兼容接口
(待译)
Upstash Redis REST compatibility face of a key-value database (kind kv): existing Redis REST clients, including @upstash/redis, work against a database of this platform by changing only the URL and the token. Base URL: https://api.deepraxis.com/redis/<database_id>, where database_id is the id (db_…) of a database created with kind kv; the token is a Praxis API key sent as Authorization: Bearer <key>, never an Upstash token. Send one command as a JSON array to POST /redis/<database_id>, a batch to /pipeline, a transaction to /multi-exec. The path form also works: GET or POST /redis/<database_id>/<command>/<arg>/<arg>… names the command in the path, and for POST the request body becomes the last argument. With the header Upstash-Encoding: base64 (which @upstash/redis sends by default) every string in a reply is base64-encoded; without it strings come back as plain text. Unlike Upstash, the platform serves one Redis 7 command set: no Lua scripting (EVAL), blocking commands, Pub/Sub or Streams; there is no Upstash management API, no global replication and no per-database token (the Praxis API key is the credential). Limits: a value and a request body are at most 1 MiB, a key at most 1 KiB, a pipeline or transaction at most 1000 commands, one reply at most 8 MiB (above that the reply is ERR reply exceeds 8 MiB; read in ranges with SCAN, HSCAN, LRANGE or ZRANGE), and a database at most 1 GiB. A credential that is read-only for the database may run read commands only; a write returns 403 NOPERM this credential is read-only for <database_id>. A table database (kind table) answers 400 ERR database <id> is not a key-value database, and an unknown id answers 404 ERR database not found. Errors have the Upstash shape: a JSON object with a single field error that holds the Redis error text. To manage keys with typed JSON instead of Redis commands, use the keys and commands operations of the Database API.
用 Upstash 的 Redis REST 协议和官方 @upstash/redis 客户端读写一个键值库。
基础地址
https://api.deepraxis.com/redis/{database_id}
| 部分 | 含义 |
|---|---|
| {database_id} | 创建键值库时返回的 ID;每个库使用自己的地址。 |
| 令牌 | 平台 API Key,作为 Authorization: Bearer 凭据;不是 Upstash 令牌。 |
import { Redis } from "@upstash/redis";
const redis = new Redis({ url: `https://api.deepraxis.com/redis/${process.env.DATABASE_ID}`, token: process.env.PRAXIS_API_KEY,});路径与请求体
| 路径 | 请求体 |
|---|---|
| POST /redis/{database_id} | 一条命令,字符串数组,例如 ["SET","k","v"] |
| POST /redis/{database_id}/pipeline | 命令数组的数组;单条出错不影响其余 |
| POST /redis/{database_id}/multi-exec | 同上,作为一个事务执行;任一命令无法解析时整体 400 EXECABORT |
| GET|POST /redis/{database_id}/{command}/{arg}/{arg}… | 命令写在路径里;POST 的请求体作为最后一个参数 |
请求头 Upstash-Encoding: base64(@upstash/redis 默认发送)使回复里的字符串以 base64 返回,数字与 null 不变,错误文本不编码。
与 Upstash 的差异
- 不支持 Lua 脚本(EVAL)、阻塞命令、Pub/Sub 与 Streams。
- 没有 Upstash 管理 API、全球复制和按库令牌;凭据是平台 API Key。
- 对 table 库调用返回 400
ERR database <id> is not a key-value database;未知库返回 404ERR database not found。 - 只读凭证执行写命令返回 403
NOPERM this credential is read-only for <id>。
限制
| 限制 | 上限 |
|---|---|
| 键 | 1 KiB |
| 单个值 | 1 MiB |
| 单个请求体 | 1 MiB |
| 一次 pipeline 或事务的命令数 | 1000 |
| 单次回复 | 8 MiB;超出返回 ERR reply exceeds 8 MiB,请用 SCAN、HSCAN、LRANGE、ZRANGE 分段读取 |
| 单库 | 1 GiB |
错误体为 {"error": "<Redis 文本>"},与 Upstash 一致。