A Redis-protocol key-value store (Valkey) for a job queue (Sidekiq, BullMQ, Celery), a cache or sessions — declare forge.KeyValueStore once, bind it per env (the dev compose Valkey, a cluster you run, a store you buy, or Reliant hosting), and read its URL with forge.KeyValueStoreRef. Cache vs durable and why durable is the default, the sizing table, what hosting runs and refuses, no backups yet, the default telemetry and alerts, and the errors you will see.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Key Value Store?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/reliant-labs-key-value-store)
---
name: deploy/key-value-store
description: A Redis-protocol key-value store (Valkey) for a job queue (Sidekiq, BullMQ, Celery), a cache or sessions — declare forge.KeyValueStore once, bind it per env (the dev compose Valkey, a cluster you run, a store you buy, or Reliant hosting), and read its URL with forge.KeyValueStoreRef. Cache vs durable and why durable is the default, the sizing table, what hosting runs and refuses, no backups yet, the default telemetry and alerts, and the errors you will see.
---
# Key-value stores: forge.KeyValueStore
A key-value store exists only when you declare one; nothing is provisioned
otherwise. It speaks the Redis protocol (Valkey 9), so every Redis client and
queue library works unchanged. Declare it once per env in `Bundle.key_value_stores`,
bind it to a runtime, and hand its URL to workloads with `forge.KeyValueStoreRef`.
The variable names are the same in every env, so the app never changes when the
binding does.
```kcl
# deploy/kcl/dev/main.k
_queue = forge.KeyValueStore {name = "queue", runtime = forge.KeyValueStoreOnCompose {port = plugin.resolve_port("acme-dev-valkey", 6379)}}
key_value_stores = [_queue]
workloads = _workloads + [forge.valkey_workload(_queue)] # runs docker-compose.yml's `valkey`
# deploy/kcl/prod/main.k
key_value_stores = [forge.KeyValueStore {name = "queue", runtime = forge.OnHosted {}}]
# workloads.k, the same in every env
env = {REDIS_URL = forge.KeyValueStoreRef {name = "queue"}} # key defaults to url
```
`REDIS_URL` is `redis://default:<password>@<host>:<port>/0`, which most clients
take whole. `name` is an RFC-1123 label of at most 40 characters. On a cluster
or on hosting it is also the store's Service name, so no workload in the env
may share it.
## cache or durable
`mode` is what the store is for. **`"durable"` is the default.**
| | `durable` (default) | `cache` |
|---|---|---|
| persistence | AOF (fsync every second) plus RDB snapshots, on a volume | none: a restart empties it |
| full memory | **refuses the write** (`noeviction`): the client gets `OOM command not allowed` | evicts the least recently used key (`allkeys-lru`) |
| for | job queues, sessions, rate limits, anything you cannot lose | a cache you can rebuild |
A queue needs durable. An evicted key is a lost job, and a restart that
empties the store loses every queued one. BullMQ warns at startup on a store
that evicts. Sidekiq and Celery say nothing, and lose jobs on one. Pick
`cache` only for data the app can recompute. Use two stores when an app has
both a queue and a cache.
## Reading it from a queue library
```kcl
# Sidekiq (Ruby) reads REDIS_URL by itself
env = {REDIS_URL = forge.KeyValueStoreRef {name = "queue"}}
```
```kcl
# BullMQ (Node): new Worker("jobs", fn, {connection: new IORedis(process.env.REDIS_URL, {maxRetriesPerRequest: null})})
env = {REDIS_URL = forge.KeyValueStoreRef {name = "queue"}}
```
```kcl
# Celery (Python): Celery("app", broker=os.environ["CELERY_BROKER_URL"])
env = {CELERY_BROKER_URL = forge.KeyValueStoreRef {name = "queue"}} # key defaults to url
```
One `forge.KeyValueStoreRef {name, key}` reads one fact. `key` is `url`
(the default), `host`, `port`, `username` or `password`. External bindings
support only `url`, so use the URL-only env map above to keep bindings portable.
`forge.key_value_store_env("REDIS", "queue")` emits five fields (`REDIS_URL`,
`REDIS_HOST`, `REDIS_PORT`, `REDIS_USERNAME`, `REDIS_PASSWORD`); that map cannot
be used with `forge.KeyValueStoreExternal` because its non-URL refs are invalid.
For managed stores, the URL selects database 0. A store is one database, so give
each use its own store rather than a `/1` index.
## Sizing
`memory_mib` is the pod's memory (request = limit), one of the tiers below
(default 256). Valkey's `maxmemory` is a share of it, leaving headroom for the
server and, when durable, the fork that rewrites the AOF. `storage_gib` sizes a
durable store's volume (1 to 100). Unset, it is derived. It may not be smaller
than the floor: three times maxmemory, at least 1 GiB. A cache takes no
`storage_gib`. One function (`ManagedKeyValueStoreSpec.Sizing`) computes all of
this for forge, the hosted operator and the bill:
| memory_mib | CPU request / limit | maxmemory durable / cache | volume default / floor (durable) |
|---|---|---|---|
| 128 | 125m / 1000m | 76 / 102 MiB | 1 / 1 GiB |
| 256 | 125m / 1000m | 153 / 204 MiB | 1 / 1 GiB |
| 512 | 125m / 1000m | 307 / 409 MiB | 1 / 1 GiB |
| 1024 | 250m / 1000m | 614 / 819 MiB | 2 / 2 GiB |
| 2048 | 500m / 1000m | 1228 / 1638 MiB | 4 / 4 GiB |
| 4096 | 1000m / 2000m | 2457 / 3276 MiB | 8 / 8 GiB |
| 8192 | 2000m / 2000m | 4915 / 6553 MiB | 16 / 15 GiB |
The CPU limit is at least one vCPU, so a small store can burst: Valkey runs
commands on one thread, and a limit near the request throttles it at trivial
load (tail latency in the tens of milliseconds). Scheduling and the hosted bill
use the request, not the limit.
The pod also runs a metrics sidecar (redis_exporter, 32 MiB, 10m CPU).
## Where it runs
`runtime` has no default:
| Runtime | What forge does | Who can read it |
|---|---|---|
| `forge.KeyValueStoreOnCompose {port}` | the dev Valkey, the scaffolded docker-compose `valkey` service run by `forge.valkey_workload(store)`, with a committed dev password | host processes on 127.0.0.1, containers of the same compose project at `valkey:6379` |
| `forge.KeyValueStoreExternal {url}` | nothing: a store you buy or run (Upstash, Memorystore, ElastiCache). `url` is a `forge.ManagedSecret` or `forge.SecretRef`, never a literal | any workload, by the `url` key only |
| `forge.OnCluster {target}` | renders plain objects into the target namespace (a one-pod StatefulSet, its Services and config); the cluster needs nothing installed | pods in that namespace |
| `forge.OnHosted {}` | Reliant hosting runs it (below) | hosted workloads of the same env only |
On `forge.OnCluster` the password lives in the Secret `forge-kvs-<name>`, which
the env must supply. On `forge.FileSecrets` (a cluster forge creates), forge
mints it into the env's secret file and writes the Secret. Anywhere else, add
`forge.key_value_store_secret("<name>", "<namespace>", forge.OpenBaoStore {})`
(or a `forge.HostedStore`) to `required_secrets`. It generates the password once
and never rotates it.
A reference that cannot reach the store is refused at render and the error
names the fix. Examples are a pod reading the compose Valkey, or a host process
reading a hosted store.
## On Reliant hosting
Each declaration is **one dedicated Valkey pod with its own volume** in the
env's namespace, isolated like your workloads. It is not a shared server
with ACLs, and only the env's hosted workloads reach it. The platform pins the
Valkey version and moves it forward. Clients can run every command a queue
library needs (EVAL, BLMOVE, XADD, INFO, CONFIG GET, FLUSHDB). They cannot
reconfigure, replicate, stop or snapshot the server (CONFIG SET, REPLICAOF,
SHUTDOWN, SAVE, MODULE, DEBUG, MONITOR, RESTORE): those answer `NOPERM`.
- **Rolling out.** A hosted store deploys only to a control plane that
advertises `manages-key-value-stores`. Until yours does, `forge env deploy`
refuses it with that name. Meanwhile, bind the store to
`forge.KeyValueStoreExternal` in that env; the app code does not change.
- **Billing**: the pod's CPU, memory and volume, on the same meters as a
workload (`deploy/hosting`). There is no separate price list.
- **Claimable** (unclaimed) deploys: one store, at most 128 MiB.
- **Removing the declaration**: `deletion_policy = "retain"` (the default)
keeps a durable store's volume, and `"delete"` deletes it. A cache has no
volume to keep.
- **No backups yet.** A durable store survives restarts and pod moves from its
volume, but nothing copies that volume elsewhere, and there is no
point-in-time restore. If losing the volume would lose data you cannot
rebuild, keep that data in Postgres, or use a store you buy
(`forge.KeyValueStoreExternal`) with its own backups.
- It is a single node: no replicas and no failover. A node move restarts it.
A durable store reloads from its AOF on restart.
## Watched by default
A store on `forge.OnCluster` or `forge.OnHosted` gets
`forge.key_value_store_telemetry(name, mode, env)` with no line of yours. It
includes the exporter's metrics, the Valkey logs, a tcp check and a dashboard,
all as service `<name>-valkey`. In an env with observability on, it also
includes these alerts:
- `<Store>ValkeyDown` (Valkey unreachable for 5 minutes).
- `<Store>ValkeyRejectingConnections` (at maxclients).
- For a durable store:
- `<Store>ValkeyMemoryNearMax` (critical, above 90% of maxmemory: writes are about to be refused).
- `<Store>ValkeyWritesRefused` (OOM).
- `<Store>ValkeyPersistenceFailing` (an AOF write, AOF rewrite or snapshot failed; usually a full volume).
`telemetry = forge.Telemetry {...}` on the store replaces the default, and
`default_telemetry = False` turns it off.
## Errors you will see
| Message | Meaning, and the fix |
|---|---|
| `OOM command not allowed when used memory > 'maxmemory'` | a durable store is full. Drain or expire keys, or raise `memory_mib` |
| `NOPERM ... has no permissions to run the '...' command` | a denied command (above). Configure through the declaration instead |
| `storageGiB N is too small for memoryMiB M` | below the volume floor. Raise `storage_gib`, or leave it unset |
| `... does not advertise "manages-key-value-stores"` | the control plane does not run hosted stores yet. Bind the env to `forge.KeyValueStoreExternal` |
| `... on a forge.KeyValueStoreOnCompose that no workload runs` | add `forge.valkey_workload(<store>)` to the env's workloads |
## Grow off
The declaration does not change, only the runtime does. Moving from hosting to
your own cluster is a binding edit, `forge.OnHosted {}` →
`forge.OnCluster {target = ...}`, plus a `required_secrets` line. Data is not
migrated across bindings. Drain a queue before you switch, and let a cache
refill.