ScalixScalix Docs
Sign up

KV Store

Key-value store with TTL, atomic operations, and pattern matching

Overview

Scalix KV is a Redis-like key-value store scoped to your project. It supports TTL expiration, atomic increments, batch operations, and key pattern matching.

CLI

bash
# Set a key
scalix-cloud kv set user:123 '{"name": "Alice", "role": "admin"}'
 
# Set with TTL (60 seconds)
scalix-cloud kv set session:abc token123 --ttl 60
 
# Get a key
scalix-cloud kv get user:123
 
# Delete a key
scalix-cloud kv del user:123
 
# List keys
scalix-cloud kv list --prefix "user:"

REST API

Set

bash
curl -X POST https://api.scalix.world/v1/kv/set \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -d '{"key": "user:123", "value": {"name": "Alice"}, "ttl": 3600}'

Get

bash
curl -X POST https://api.scalix.world/v1/kv/get \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -d '{"key": "user:123"}'

Batch Operations

bash
# Multi-get
curl -X POST https://api.scalix.world/v1/kv/mget \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -d '{"keys": ["user:123", "user:456", "user:789"]}'
 
# Multi-set
curl -X POST https://api.scalix.world/v1/kv/mset \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -d '{"entries": [{"key": "a", "value": 1}, {"key": "b", "value": 2}]}'

Atomic Increment

bash
curl -X POST https://api.scalix.world/v1/kv/incr \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -d '{"key": "counter:visits", "delta": 1}'

TTL Management

bash
# Set expiration
curl -X POST https://api.scalix.world/v1/kv/expire \
  -d '{"key": "session:abc", "ttl": 1800}'
 
# Remove expiration
curl -X POST https://api.scalix.world/v1/kv/persist \
  -d '{"key": "session:abc"}'
 
# Check remaining TTL
curl -X POST https://api.scalix.world/v1/kv/ttl \
  -d '{"key": "session:abc"}'

List Keys

bash
curl -X POST https://api.scalix.world/v1/kv/keys \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -d '{"pattern": "user:*", "limit": 100}'

SDK

typescript
import { kvDel, kvGet, kvSet } from "@scalix-world/sdk";
 
await kvSet({ body: { key: "user:123", value: { name: "Alice" }, ttl: 3600 } });
const { data: user } = await kvGet({ body: { key: "user:123" } });
await kvDel({ body: { keys: ["user:123"] } });

Atomic increment is available over REST at POST /v1/kv/incr:

bash
curl -X POST https://api.scalix.world/v1/kv/incr \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "counter:visits"}'