Redis storage driver
Understand Redis and Valkey records, atomic commits, limits, operator reads, and hints.
@runlane/redis-storage exports createRedisStorageDriver(). It implements raw storage, ordered observation append, operator reads, and optional run and work hints. Runlane core owns task lifecycle rules. For deployment steps, use Redis polling, Redis Streams, or Redis and SQS.
Create the driver
import { createRedisStorageDriver } from '@runlane/redis-storage'
export async function openRedisDriver(url: string) {
const driver = createRedisStorageDriver({ url, namespace: 'billing-jobs' })
await driver.start?.()
return driver
}Raw storage/transport compositions set workHints: false because transport delivery does not consume storage work hints.
The caller owns driver.close(). A composed lane closes the driver for you. Keep one driver per independently closed runtime. See Redis options for connection ownership, limits, and startup diagnostics.
The profile is durable, server_sampled, and strong, with advisory candidate selection. These are storage profile values. Transaction time comes from TIME routed through the namespace primary. It is a sampled server time, without Postgres's post-lock clock guarantee.
Durability
Redis may lose recent writes on crash or failover depending on your persistence settings; affected runs behave like retries. A server that restarts with no persistence loses every run. Make external effects safe to repeat.
Runlane does not check persistence by default, because managed services hide those settings. Configure it on the deployment: AOF or RDB snapshots on a self-hosted server, or the durability setting of a managed service. Set startupChecks: { persistence: true } to log a startup warning when persistence looks disabled or cannot be checked. See startup checks.
Key layout and Cluster scope
The namespace owns isolation and the physical prefix. All storage keys share one Cluster hash tag, so one namespace lives on one primary. A single transaction can update shared queue capacity, a run, child records, owners, and history in that slot. Cluster can place separate namespaces on different primaries; it cannot spread one namespace across primaries.
Let N identify the encoded namespace. Provider-owned keys have this layout:
| Key | Contents |
|---|---|
runlane:{N}:meta | Physical format, storage contract version, and store generation. |
runlane:{N}:v1:r:<record-key> | Hash containing the opaque version, canonical JSON document, and supplied raw indexes. |
runlane:{N}:v1:i:<index>:<partition-key> | Sorted set for one named raw index partition. |
runlane:{N}:v1:op:<scope> | Derived sorted sets for run and event queries. |
Canonical records and indexes have no expiry. Retention is a core transaction, followed by bounded cleanup. Pub/sub channels carry hints separately. The Streams transport owns its own runlane-delivery: keys and namespace.
Use the public storage API to change records. Direct key edits can break version fences, indexes, or marker compatibility. Physical names and index members belong to the provider.
What Runlane sets up in Redis
Runlane stores a runlane:{encoded-namespace}:meta marker with the physical format version, storage contract version, and a unique generation. It fences incompatible formats and namespace resets. The accepted marker and records have no expiry.
On first use, Runlane refuses an unrecognized nonempty namespace. Each commit is one atomic script call, so a new namespace first checks that the server and any proxy accept requests up to the storage contract floor. One synthetic script call covers the real floor envelopes' byte size, key and argument counts, and largest argument. For a UUID namespace it sends about 29 MB once and needs about 50 MiB of extra JavaScript memory, plus network buffers. Existing namespaces skip this check.
Concurrent starters wait for initialization. Its temporary reservation lasts 30 seconds and renews every 10 seconds. A crashed first starter frees the namespace within 30 seconds of its last renewal.
Every commit checks the marker's exact generation. An incompatible marker, or one changed beneath a running driver, produces non-retryable configuration_invalid. Startup does not convert an existing format. There is no Redis migration CLI.
See startup checks for failures, warnings, and first-initialization request cost.
Atomic compare-and-commit
The transaction callback runs in TypeScript. Reads record exact versions, including absent records. Writes stay staged until the callback finishes. The driver prepares the complete key list, new records, index differences, and operator projections before sending one Lua commit.
The script checks the marker, read-set versions, key types, argument shapes, and write permissions before its first mutation. It then changes canonical records and their indexes together. A conflict applies no writes and permits a bounded callback replay. Read-only attempts validate their read set too. Keep external effects outside transaction callbacks.
Every accessed key is passed explicitly through KEYS, as required by Valkey EVAL. The driver caches each script identity and falls back from EVALSHA to EVAL only for a definite NOSCRIPT response. Cluster routing retries are limited to definite pre-execution failures. A lost response may follow a successful commit: the driver reports storage_unavailable and does not replay the uncertain request or callback.
New versions are random positive decimal values used only for equality checks. Deleting and recreating a record does not restore an old version. Ordered append allocates observation positions and their head in the same commit through the canonical storage materializer; it does not use Redis Stream IDs.
Limits and bounded reads
Storage applies contractDefaults.storage.maxRecordBytes, minTransactionRecords, and minTransactionBytes. The driver supports those capacity floors and uses them as its logical transaction budgets. Its transaction limit is 25 records, matching contractDefaults.storage.minTransactionRecords; this provider does not support larger mutating transactions. A mutating attempt counts its read dependencies, including absent keys. Physical request size is also bounded. Oversize attempts fail with storage_limit_exceeded before any write, with meta.actual and meta.limit.
There is no configurable limits option. Point reads accept larger key lists and chunk them internally. Raw index queries return bounded pages with canonical cursors; callers follow the cursor while more records may exist. A record remains an opaque JSON document; core codecs own its shape.
Use Redis options for provider budgets. Stored record size is not wire request size: replacement requests also include keys, prior index removals, and derived memberships.
Operator reads
getRun(), listRuns(), and listRunEvents() read canonical records. Derived sorted sets support the public run and event sorts and filter facets. Scope and facet names use fixed-size digests. Reads verify the real fields and full filter conjunction against each canonical document.
Each bounded window loads its records atomically. Reads discard stale memberships and de-duplicate record keys across windows in one page. Events are checked together with their owning run's visibility. Unrelated writes do not force a page retry. These are keyset page semantics, not one snapshot held across a whole listing.
Tombstoning hides a run and its events immediately while core removes children in bounded pages. Unrecognized opaque raw documents remain valid raw storage but do not populate the operator model. No Redis Search module is required.
Work and run hints
driver.workSignal serves polling workers. workHints defaults to contractDefaults.delivery.workHints (true) on raw storage and the polling lane. When false, it sends no work publications and exposes an empty driver.workSignal, with no start or wait. Core then uses local commit wakes and polling. Streams and SQS lanes force it off because their transports deliver work; those lanes reject the option.
driver.runSignal serves run subscriptions when runHints is enabled. The driver and all three ready-made Redis lanes use contractDefaults.realtime.runHints (true).
Hints only lower latency. Polling with idle backoff guarantees progress while storage and worker capacity are available. Delays, retries, schedules, and lease expiry always depend on polling and maintenance.
One dedicated pub/sub listener is shared by active work and run waits on a driver. It opens lazily. It carries identities, not task payloads or output values. Registering a wait happens before the authoritative read; listener readiness wakes waits to close the setup gap. Listener loss releases waits, and a later wait can reopen it. Timeouts preserve polling when pub/sub is unavailable.
Hints publish after commit. Nearby changes share a leading hint and one trailing hint per channel and payload. Hint failure cannot fail committed data. Failures use observeBackgroundFailures() and project telemetry. Closing releases waits and drains pending publications before closing owned connections.
Verify provider changes
The live suites cover Redis and Valkey on standalone, Sentinel, and Cluster, including conflicts, limits, topology changes, response loss, operator parity, and shutdown. Use provider conformance alongside tests against the actual deployment. See connection and managed-service scope before choosing a hosted service.