Skip to content

Feat/expire ttl#13

Merged
phaethix merged 2 commits into
masterfrom
feat/expire-ttl
Apr 30, 2026
Merged

Feat/expire ttl#13
phaethix merged 2 commits into
masterfrom
feat/expire-ttl

Conversation

@phaethix
Copy link
Copy Markdown
Owner

No description provided.

Introduce an internal ValueEntry carrying an optional monotonic deadline, and expose expire_at_ms / persist / ttl_ms / sweep_expired on KvEngine. All read and write paths honour the deadline: lazy expiration drops stale entries on access, and sweep_expired supports an adaptive background sampler.

The AOF writer learns two new records, PEXPIREAT (absolute epoch ms) and PERSIST, and the replay loader applies them. PEXPIREAT entries whose deadline is already past cause the key to be dropped during replay, keeping the log idempotent across restarts. SET overwrites clear the existing TTL to match Redis semantics; INCR and APPEND preserve it.
…ctive expiration sweeper

Extend the RESP2 parser and the command executor with the full TTL command family. EXPIRE/PEXPIRE translate relative offsets into absolute epoch milliseconds before calling the engine, so replay always sees a stable deadline. TTL returns whole seconds (rounded up from the remaining millis) and PTTL returns the raw millisecond count; both surface the Redis -2 / -1 sentinels.

Add a dedicated background sweeper (storage::expire) that samples twenty keys every hundred milliseconds and follows up immediately when more than a quarter of the sample was expired. The main binary spawns the sweeper on startup and joins it during graceful shutdown. End-to-end tests cover the new wire contract as well as the sweeper actually evicting keys without a foreground read.
@phaethix phaethix merged commit d45b00d into master Apr 30, 2026
1 check passed
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