跳转到内容
EN

命令、批量与事务

数据库 API →

基础地址、差异与限制

执行命令

POST /redis/{database_id}

参数 位置 说明
database_id path 键值库的 ID。
Upstash-Encoding header 设为 base64 时,回复里的字符串以 base64 返回;省略则为明文。
const result = await redis.set("greeting", "hello");
console.log(result);

响应

HTTP 200

Success

application/json

名称 类型 说明
result any Redis's reply for the command: an integer, a string, an array (possibly nested) or null; strings are base64 when Upstash-Encoding: base64 was sent. Absent when error is present.
error string Redis's own error text for this command, for example WRONGTYPE Operation against a key holding the wrong kind of value; never base64-encoded. Absent when the command succeeded.
终端窗口
curl -X POST "https://api.deepraxis.com/redis/${DATABASE_ID}/pipeline" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '[["set","greeting","hello"]]'

响应示例 — HTTP 200

[
{
"result": "OK"
}
]

批量执行

POST /redis/{database_id}/pipeline

参数 位置 说明
database_id path 键值库的 ID。
Upstash-Encoding header 设为 base64 时,回复里的字符串以 base64 返回;省略则为明文。
const result = await redis.pipeline().set("hits", 0).incr("hits").get("hits").exec();
console.log(result);

响应

HTTP 200

Success

application/json

名称 类型 说明
[].result any Redis's reply for the command: an integer, a string, an array (possibly nested) or null; strings are base64 when Upstash-Encoding: base64 was sent. Absent when error is present.
[].error string Redis's own error text for this command, for example WRONGTYPE Operation against a key holding the wrong kind of value; never base64-encoded. Absent when the command succeeded.
终端窗口
curl -X POST "https://api.deepraxis.com/redis/${DATABASE_ID}/pipeline" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '[["set","hits",0],["incr","hits"],["get","hits"]]'

响应示例 — HTTP 200

[
{
"result": "OK"
},
{
"result": 1
},
{
"result": "1"
}
]

事务执行

POST /redis/{database_id}/multi-exec

参数 位置 说明
database_id path 键值库的 ID。
Upstash-Encoding header 设为 base64 时,回复里的字符串以 base64 返回;省略则为明文。
const result = await redis.multi().incr("balance").lpush("log", "credited").exec();
console.log(result);

响应

HTTP 200

Success

application/json

名称 类型 说明
[].result any Redis's reply for the command: an integer, a string, an array (possibly nested) or null; strings are base64 when Upstash-Encoding: base64 was sent. Absent when error is present.
[].error string Redis's own error text for this command, for example WRONGTYPE Operation against a key holding the wrong kind of value; never base64-encoded. Absent when the command succeeded.
终端窗口
curl -X POST "https://api.deepraxis.com/redis/${DATABASE_ID}/multi-exec" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '[["incr","balance"],["lpush","log","credited"]]'

响应示例 — HTTP 200

[
{
"result": 1
},
{
"result": 1
}
]