Skip to content

Commit dd3a1c0

Browse files
authored
feat(run-store): Redis-backed store for the run execution-state log (#4754)
Adds `RedisSnapshotStore` to `@internal/run-store`: a Redis-backed, append-only store for a run's execution-state log, as an alternative to keeping that log in Postgres. Nothing constructs it. No existing code path can reach it, so merging this changes no behaviour. The store, the wiring that would use it, and the switch that would enable it are deliberately separate changes. ## Design Four keys per run, plus one key per wait cycle, all sharing a `{runId}` hash tag. Every mutation for a run therefore lands in one cluster slot, and each operation is a single Lua script. No script mints a key name. Dynamic keys are derived from `KEYS[1]` by string surgery, because ioredis applies `keyPrefix` only to the KEYS array: a key built inside Lua would be unprefixed while the client wrote a prefixed one. Retention is keyed to run completion. A non-terminal run's keys carry no expiry at all, since a suspended run can wait indefinitely with nothing left to refresh a TTL. The terminal transition sets the completion expiry once, and a write arriving after completion re-applies that same expiry rather than a live one, so a stale client cannot resurrect a key. Entry JSON round-trips byte for byte. No script calls `cjson`, and the values the store assigns itself live in their own hash fields instead of being patched into the caller's document. Sizes are observed, never enforced. Entry and cycle-key bytes are recorded, with a warning above a configurable mark. Nothing rejects, truncates, or spills. `append` takes an optional expected-current-snapshot argument. Left out, it advances the pointer unconditionally, matching the Postgres behaviour it replaces. Supplied, it advances only on a match and otherwise reports the conflict without writing. Covered by 48 tests against a real Redis container, including the retention transitions, the single-slot guarantee under a key prefix, and tenant-scoped reads.
1 parent 910011d commit dd3a1c0

5 files changed

Lines changed: 1898 additions & 0 deletions

File tree

‎internal-packages/run-store/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
},
1616
"dependencies": {
17+
"@internal/redis": "workspace:*",
1718
"@trigger.dev/core": "workspace:*",
1819
"@trigger.dev/database": "workspace:*"
1920
},

‎internal-packages/run-store/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./types.js";
22
export * from "./PostgresRunStore.js";
33
export * from "./runOpsStore.js";
44
export * from "./readReplicaClient.js";
5+
export * from "./redisSnapshotStore.js";

0 commit comments

Comments
 (0)