跳转到内容
EN

键

指南 →

基础地址与鉴权

仅在 /database/v1/kv 下可用;用表格库的 ID 访问返回 404 DATABASE_NOT_FOUND。读取需要读权限的凭证,写入需要读写权限的凭证。

限制:键最长 1 KiB,单个值最长 1 MiB,单次回复最长 8 MiB(用 SCAN、HSCAN、LRANGE、ZRANGE 分段读取),单库最大 1 GiB。

需要直接对接 Redis 客户端时使用 Upstash 兼容接口。

列出键

GET /database/v1/kv/{database_id}/keys

参数 位置 说明
database_id path 库 ID。
limit query 最多返回的条数。 (default: 50) (1–500)
cursor query 上一页返回的 next_cursor。
pattern query Redis glob(* ? [abc] [^abc]),匹配整个键名,例如 user:*;省略则不过滤。
type query 只返回该类型的键:string、hash、list、set 或 zset;省略则不过滤。

返回: object.

响应

HTTP 200

Success

application/json

名称 类型 说明
data array<object> Key summaries on this page in lexicographic key order; empty when nothing matches.
data[].key string The key name; pass it percent-encoded as the key path parameter of the key operations.
data[].type string Value type stored under the key.
data[].ttl_ms integer | null Time to live in milliseconds, remaining until the key expires; null when the key never expires.
data[].size_bytes integer Stored size of the value in bytes.
next_cursor string | null Cursor for the next page, passed back unchanged as cursor; null when this is the last page.
终端窗口
curl -X GET "https://api.deepraxis.com/database/v1/kv/${DATABASE_ID}/keys?pattern=user%3A*&limit=10" \
-H "Authorization: Bearer $PRAXIS_API_KEY"

响应示例 — HTTP 200

{
"data": [
{
"key": "user:1",
"type": "hash",
"ttl_ms": 3599183,
"size_bytes": 16
}
],
"next_cursor": null
}

读取键

GET /database/v1/kv/{database_id}/keys/{key}

参数 位置 说明
database_id path 库 ID。
key path 键名:任意 UTF-8 字符串,最长 1 KiB;放进路径时需百分号编码,例如 user%3A1。
limit query 最多返回的条数。 (default: 100) (1–1000)
cursor query 上一页返回的 next_cursor。

返回: Key.

响应

HTTP 200

Success

application/json

名称 类型 说明
key string The key name.
type string Value type stored under the key; it decides the shape of value.
ttl_ms integer | null Time to live in milliseconds, remaining until the key expires; null when the key never expires.
size_bytes integer Stored size of the whole value in bytes, not of this page.
value string | array<string | object> The value in the shape of type: a string; hash as [{field, value}]; list and set as a string array; zset as [{member, score}]. For a container this is one page; read the rest with next_cursor.
next_cursor string | null Cursor for the next page of a container value, passed back unchanged as cursor; null for a string value and on the last page.
终端窗口
curl -X GET "https://api.deepraxis.com/database/v1/kv/${DATABASE_ID}/keys/user%3A1" \
-H "Authorization: Bearer $PRAXIS_API_KEY"

响应示例 — HTTP 200

{
"key": "user:1",
"type": "hash",
"ttl_ms": 3598632,
"size_bytes": 16,
"value": [
{
"field": "name",
"value": "Ada"
},
{
"field": "role",
"value": "admin"
}
],
"next_cursor": null
}

写入键

PUT /database/v1/kv/{database_id}/keys/{key}

参数 位置 说明
database_id path 库 ID。
key path 键名:任意 UTF-8 字符串,最长 1 KiB;放进路径时需百分号编码,例如 user%3A1。

请求体

字段 类型 必填 说明
type "string" / "hash" / "list" / "set" / "zset" 是 类型
value string / string / object[] 是 值,形状随 type:string 为字符串;hash 为 [{field, value}];list 与 set 为字符串数组;zset 为 [{member, score}]
ttl_ms integer / null 否 剩余生存时间(毫秒);null 表示永不过期。写入时:省略保持原 TTL,正整数设置新 TTL,null 设为永久

返回: Key.

响应

HTTP 200

Success

application/json

名称 类型 说明
key string The key name.
type string Value type stored under the key; it decides the shape of value.
ttl_ms integer | null Time to live in milliseconds, remaining until the key expires; null when the key never expires.
size_bytes integer Stored size of the whole value in bytes, not of this page.
value string | array<string | object> The value in the shape of type: a string; hash as [{field, value}]; list and set as a string array; zset as [{member, score}]. For a container this is one page; read the rest with next_cursor.
next_cursor string | null Cursor for the next page of a container value, passed back unchanged as cursor; null for a string value and on the last page.
终端窗口
curl -X PUT "https://api.deepraxis.com/database/v1/kv/${DATABASE_ID}/keys/user%3A1" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"type":"hash","value":[{"field":"name","value":"Ada"},{"field":"role","value":"admin"}],"ttl_ms":3600000}'

响应示例 — HTTP 200

{
"key": "user:1",
"type": "hash",
"ttl_ms": 3600000,
"size_bytes": 16,
"value": [
{
"field": "name",
"value": "Ada"
},
{
"field": "role",
"value": "admin"
}
],
"next_cursor": null
}

更新键

PATCH /database/v1/kv/{database_id}/keys/{key}

参数 位置 说明
database_id path 库 ID。
key path 键名:任意 UTF-8 字符串,最长 1 KiB;放进路径时需百分号编码,例如 user%3A1。

请求体

字段 类型 必填 说明
update_mask "ttl_ms" 是 要更新的字段,只能是 ttl_ms
ttl_ms integer / null 是 剩余生存时间(毫秒);null 表示永不过期。写入时:省略保持原 TTL,正整数设置新 TTL,null 设为永久

返回: Key.

响应

HTTP 200

Success

application/json

名称 类型 说明
key string The key name.
type string Value type stored under the key; it decides the shape of value.
ttl_ms integer | null Time to live in milliseconds, remaining until the key expires; null when the key never expires.
size_bytes integer Stored size of the whole value in bytes, not of this page.
value string | array<string | object> The value in the shape of type: a string; hash as [{field, value}]; list and set as a string array; zset as [{member, score}]. For a container this is one page; read the rest with next_cursor.
next_cursor string | null Cursor for the next page of a container value, passed back unchanged as cursor; null for a string value and on the last page.
终端窗口
curl -X PATCH "https://api.deepraxis.com/database/v1/kv/${DATABASE_ID}/keys/user%3A1" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"update_mask":"ttl_ms","ttl_ms":600000}'

响应示例 — HTTP 200

{
"key": "user:1",
"type": "hash",
"ttl_ms": 600000,
"size_bytes": 16,
"value": [
{
"field": "name",
"value": "Ada"
},
{
"field": "role",
"value": "admin"
}
],
"next_cursor": null
}

删除键

DELETE /database/v1/kv/{database_id}/keys/{key}

参数 位置 说明
database_id path 库 ID。
key path 键名:任意 UTF-8 字符串,最长 1 KiB;放进路径时需百分号编码,例如 user%3A1。

返回: object.

响应

HTTP 200

Success

application/json

名称 类型 说明
deleted boolean True when the key existed and was removed; false when it was absent or had already expired.
终端窗口
curl -X DELETE "https://api.deepraxis.com/database/v1/kv/${DATABASE_ID}/keys/user%3A1" \
-H "Authorization: Bearer $PRAXIS_API_KEY"

响应示例 — HTTP 200

{
"deleted": true
}

KeySummary

字段 类型 必填 说明
key string 是 键名
type "string" / "hash" / "list" / "set" / "zset" 是 类型
ttl_ms integer / null 是 剩余生存时间(毫秒);null 表示永不过期。写入时:省略保持原 TTL,正整数设置新 TTL,null 设为永久
size_bytes integer 是 占用字节数

Key

字段 类型 必填 说明
key string 是 键名
type "string" / "hash" / "list" / "set" / "zset" 是 类型
ttl_ms integer / null 是 剩余生存时间(毫秒);null 表示永不过期。写入时:省略保持原 TTL,正整数设置新 TTL,null 设为永久
size_bytes integer 是 占用字节数
value string / string / object[] 是 值,形状随 type:string 为字符串;hash 为 [{field, value}];list 与 set 为字符串数组;zset 为 [{member, score}]
next_cursor string / null 是 下一页游标,原样传回 cursor;没有后续时为 null