Skip to content

feat: add memory-authoritative write-behind mode for Redis - #1

Merged
mysamimi merged 1 commit into
masterfrom
feat/memory-authoritative-write-behind
Jun 10, 2026
Merged

feat: add memory-authoritative write-behind mode for Redis#1
mysamimi merged 1 commit into
masterfrom
feat/memory-authoritative-write-behind

Conversation

@mysamimi

Copy link
Copy Markdown
Owner

Adds an optional "memory-authoritative" mode where Redis is used purely as an async write-behind layer, keeping the hot path fully in-memory after warmup. All changes are backward-compatible (defaults preserve existing read-through behavior).

  • Single round-trip Redis reads via optional RedisGetTTLClient interface (implemented by v8/v9 adapters with a GET+TTL pipeline); falls back to separate Get+TTL otherwise.
  • WithWriteThroughOnly(): disables synchronous Redis reads on local miss for Get/getFallback/ModifyNumeric/SetNX; writes still flow async.
  • WarmFromRedis(keys): loads state from Redis into memory at startup for durability across restarts without runtime synchronous reads.
  • Local-authoritative SetNX in write-through-only mode: atomicity via the local shard lock, async SETNX to Redis; default behavior preserved.
  • Fix silent drop-on-full: centralize async sends through enqueueRedis, count drops via DroppedWrites(), and add WithBlockOnFull(d) to block briefly instead of dropping.
  • Tests for all new behavior (miniredis-backed, no external Redis needed).
  • README updated with new features and clarified read-through semantics.

Adds an optional "memory-authoritative" mode where Redis is used purely as
an async write-behind layer, keeping the hot path fully in-memory after
warmup. All changes are backward-compatible (defaults preserve existing
read-through behavior).

- Single round-trip Redis reads via optional RedisGetTTLClient interface
  (implemented by v8/v9 adapters with a GET+TTL pipeline); falls back to
  separate Get+TTL otherwise.
- WithWriteThroughOnly(): disables synchronous Redis reads on local miss
  for Get/getFallback/ModifyNumeric/SetNX; writes still flow async.
- WarmFromRedis(keys): loads state from Redis into memory at startup for
  durability across restarts without runtime synchronous reads.
- Local-authoritative SetNX in write-through-only mode: atomicity via the
  local shard lock, async SETNX to Redis; default behavior preserved.
- Fix silent drop-on-full: centralize async sends through enqueueRedis,
  count drops via DroppedWrites(), and add WithBlockOnFull(d) to block
  briefly instead of dropping.
- Tests for all new behavior (miniredis-backed, no external Redis needed).
- README updated with new features and clarified read-through semantics.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mysamimi
mysamimi merged commit 3b9f714 into master Jun 10, 2026
1 check passed
@mysamimi
mysamimi deleted the feat/memory-authoritative-write-behind branch June 10, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant