Key-value databases
A key-value database is the second kind of Database: it stores strings, hashes, lists, sets and sorted sets by key, with optional expiry. It is compatible with the Upstash Redis REST interface, so existing @upstash/redis code only needs a new URL and token.
Key-value or table
The path is the type: the path a database is created under decides its type, and the type never changes.
| Type | Path | Stores | Access | Fits |
|---|---|---|---|---|
| Table database | /database/v1/table | Tables and rows with typed fields | Supabase-compatible interface | Catalogs, itineraries and operating data you filter and link |
| Key-value database | /database/v1/kv | Keys and values, optionally expiring | Upstash Redis-compatible interface, native key interface | Caches, counters, sessions, rate limits, leaderboards, de-duplication sets |
Reaching a database through the other type’s path, for example a table database’s id on /database/v1/kv/{database_id}, returns 404 DATABASE_NOT_FOUND, the same as an unknown id. The create body takes no kind; one that carries it returns 400 INVALID_PARAMS, and kind in a response is read-only. Deletion (recoverable for 7 days), permanent purge, labels and ownership are the same as for table databases; see Concepts.
Create a key-value database
Prerequisites: an API key in the PRAXIS_API_KEY environment variable, and key-value databases opened for your organization. When they are not, creation returns 400 INVALID_PARAMS with the message kind kv is not available.
curl -X POST "https://api.deepraxis.com/database/v1/kv" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Session cache" }'const database = await praxis.database.kv.create({ body: { name: "Session cache" },});console.log(database.id);Expect: the returned database has kind kv, and its id is the <database_id> used below. You can also create one from the Console database list by choosing the type “Key-value”.
Connect with @upstash/redis
Two values are enough:
| Environment variable | Value |
|---|---|
UPSTASH_REDIS_REST_URL | https://api.deepraxis.com/redis/<database_id> |
UPSTASH_REDIS_REST_TOKEN | A platform API key |
npm install @upstash/redisSave the following as kv.mjs, set the two variables, and run node kv.mjs.
import { Redis } from "@upstash/redis";
const redis = Redis.fromEnv();// Equivalent: new Redis({ url: process.env.UPSTASH_REDIS_REST_URL, token: process.env.UPSTASH_REDIS_REST_TOKEN })
console.log(await redis.set("greeting", "hello")); // OKconsole.log(await redis.get("greeting")); // helloconsole.log(await redis.incr("counter")); // 1
// Expiry: the key disappears after 100 secondsawait redis.set("session:1", "alice", { ex: 100 });console.log(await redis.ttl("session:1")); // greater than 0console.log(await redis.persist("session:1")); // 1, expiry removedconsole.log(await redis.ttl("session:1")); // -1
// Hash, list, sorted setawait redis.hset("user:1", { name: "alice", plan: "pro" });console.log(await redis.hgetall("user:1")); // { name: "alice", plan: "pro" }await redis.rpush("queue", "a", "b", "c");console.log(await redis.lrange("queue", 0, -1)); // [ "a", "b", "c" ]await redis.zadd("board", { score: 1, member: "a" }, { score: 2, member: "b" });console.log(await redis.zrange("board", 0, -1)); // [ "a", "b" ]
// Pipeline: several commands in one requestconst results = await redis.pipeline().set("p", "1").incr("p").get("p").exec();console.log(results); // [ "OK", 2, 2 ]
// Multi-exec: run as one unitconsole.log(await redis.multi().set("m", "1").incr("m").exec()); // [ "OK", 2 ]Expect: each line prints what its comment says. The SDK parses values it reads as JSON, so a string written as "1" may read back as the number 1; convert it yourself when you need a string.
Without the SDK, send HTTP directly:
curl -X POST "https://api.deepraxis.com/redis/$DATABASE_ID" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d '["SET","greeting","hello"]'Expect: {"result":"OK"}.
HTTP entry points, all under /redis/<database_id>:
| Request | Effect |
|---|---|
POST /redis/<id> | The body is one command array, such as ["GET","k"] |
POST /redis/<id>/pipeline | The body is an array of command arrays, run in one request; returns [{ "result": … } or { "error": … }, …], one item per command |
POST /redis/<id>/multi-exec | Like pipeline, but run as one unit; if any command cannot be parsed the whole request returns 400 EXECABORT and nothing runs |
GET /redis/<id>/set/k/v | Path style: the command name and arguments go in the path |
With the header Upstash-Encoding: base64, string replies are base64-encoded. @upstash/redis sends it by default; you need not handle it.
Native key interface
Use the native interface when you do not want a Redis client, or to browse keys from a script. Fields are snake_case; authentication is the same as the other Database interfaces.
| Operation | HTTP | SDK |
|---|---|---|
| List keys | GET /database/v1/kv/{database_id}/keys | praxis.database.kv.keys.list |
| Read a key | GET /database/v1/kv/{database_id}/keys/{key} | praxis.database.kv.keys.retrieve |
| Write a whole value | PUT /database/v1/kv/{database_id}/keys/{key} | praxis.database.kv.keys.set |
| Change expiry | PATCH /database/v1/kv/{database_id}/keys/{key} | praxis.database.kv.keys.update |
| Delete | DELETE /database/v1/kv/{database_id}/keys/{key} | praxis.database.kv.keys.delete |
| Run one command | POST /database/v1/kv/{database_id}/commands | praxis.database.kv.commands.execute |
- List keys:
limitdefaults to 50, maximum 500;cursorpages;patternis a Redis glob;typefilters by type. Returns{ "data": [{ "key", "type", "ttl_ms", "size_bytes" }], "next_cursor" }. - Read a key: container values (hash, list, set, sorted set) are paged;
limitdefaults to 100, maximum 1000. A missing key returns 404KEY_NOT_FOUND. - Write a whole value: body
{ "type", "value", "ttl_ms" }replaces the whole value. Omitttl_msto keep the existing expiry; a number is milliseconds;nullmeans no expiry. - Change expiry: body
{ "update_mask": "ttl_ms", "ttl_ms": 60000 }. - Delete: returns
{ "deleted": true }, or{ "deleted": false }when the key did not exist. - Run a command: body
{ "command": ["HGETALL", "user:1"] }, returns{ "result": ... }. When Redis rejects the command the response is 400KV_COMMAND_ERRORandmessageis Redis’s own text, such asWRONGTYPE Operation against a key holding the wrong kind of value.
curl -X POST "https://api.deepraxis.com/database/v1/kv/$DATABASE_ID/commands" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "command": ["GET", "greeting"] }'Expect: {"result":"hello"} (the key was written in the previous section).
Full fields: keys, commands and the Upstash-compatible API.
Supported commands
Command names are case-insensitive.
| Category | Commands |
|---|---|
| Strings | GET SET (supports NX XX GET KEEPTTL EX PX EXAT PXAT) SETNX SETEX PSETEX GETSET GETDEL GETEX MGET MSET MSETNX INCR DECR INCRBY DECRBY INCRBYFLOAT APPEND STRLEN GETRANGE SETRANGE |
| Keys and expiry | DEL UNLINK EXISTS EXPIRE PEXPIRE EXPIREAT PEXPIREAT TTL PTTL PERSIST TYPE RENAME RENAMENX KEYS RANDOMKEY DBSIZE FLUSHDB |
| Hashes | HSET HSETNX HGET HMGET HGETALL HDEL HEXISTS HLEN HKEYS HVALS HINCRBY HINCRBYFLOAT HSTRLEN |
| Lists | LPUSH RPUSH LPUSHX RPUSHX LPOP RPOP LLEN LRANGE LINDEX LSET LREM LTRIM LPOS LMOVE |
| Sets | SADD SREM SMEMBERS SISMEMBER SMISMEMBER SCARD SPOP SRANDMEMBER SINTER SUNION SDIFF SINTERSTORE SUNIONSTORE SDIFFSTORE SMOVE |
| Sorted sets | ZADD ZREM ZSCORE ZMSCORE ZINCRBY ZCARD ZCOUNT ZRANK ZREVRANK ZRANGE ZREVRANGE ZRANGEBYSCORE ZREVRANGEBYSCORE ZREMRANGEBYRANK ZREMRANGEBYSCORE ZPOPMIN ZPOPMAX |
| Incremental iteration | SCAN (supports MATCH COUNT TYPE) HSCAN SSCAN ZSCAN |
| Other | PING ECHO |
Not supported:
- Lua scripts:
EVAL,EVALSHA. - Blocking commands:
BLPOP,BRPOPand the like. - Publish/subscribe (Pub/Sub).
- Streams.
- Multi-database
SELECT: a key-value database is one keyspace.
A command outside the table above returns ERR unknown command '<name>'.
Limits
| Limit | Maximum |
|---|---|
| Key length | 1024 bytes |
| One value | 1 MiB |
| One request body | 1 MiB |
| Commands in one pipeline or multi-exec | 1000 |
| Reply of one call (for a pipeline, all results added up) | 8 MiB |
| One database | 1 GiB |
A reply above 8 MiB returns ERR reply exceeds 8 MiB; read it in ranges (SCAN/HSCAN/LRANGE/ZRANGE with limits): read in ranges with SCAN, HSCAN, LRANGE or ZRANGE. SPOP, LPOP, RPOP, ZPOPMIN and ZPOPMAX with a count are rejected when their reply is over the limit, and the data is unchanged. When the database is full, write commands return OOM command not allowed when used memory > 'maxmemory'.. Expiry is checked on read, so an expired key cannot be read; a background job reclaims its space on a schedule. Other errors are in Limits and errors.
Permissions
A read-write credential can run every supported command. A read-only credential (resource scope access of read) can run read commands only; a write command returns 403:
NOPERM this credential is read-only for <database_id>A command that cannot be parsed is treated as a write, so it also returns 403 for a read-only credential. On the native key interface, a write with a read-only credential returns 403 BINDING_READ_ONLY. Give callers that only read a read-only credential.
Performance
Each call is one network round trip to Hong Kong; the read or write then completes where the database lives, with no further network hop. Measured hot requests take about 40 ms to first byte from a US client, TLS included; a 100-command pipeline takes about as long as one command.
It can replace a serverless Redis such as Upstash; it is not a sub-millisecond in-memory Redis. Batch frequent small commands into a pipeline so they share one round trip.
Inspect and troubleshoot
- Console: a key-value database’s detail page has Keys (browse, filter by pattern, edit values and expiry, create keys), Command line (run commands one at a time), Connect (the REST URL and an
@upstash/redisexample) and Settings tabs. - From a script:
praxis.database.kv.keys.listlists keys by pattern and type;praxis.database.kv.commands.executeruns one command and shows its result. - On an error: see Limits and errors.
Next steps
- Limits and errors: the key-value limits and error codes.
- Upstash-compatible API: the full reference for HTTP entry points and command replies.
- Keys · Commands: fields of the native interface.
- Concepts: database lifecycle, deletion and recovery.