Skip to content

feat: batch doFetch/doSave through ephpm_kv_mget/mset (ePHPm v0.13) - #4

Merged
luthermonson merged 1 commit into
mainfrom
feat/kv-v013
Oct 22, 2026
Merged

luthermonson merged 1 commit into
mainfrom
feat/kv-v013

Conversation

@luthermonson

Copy link
Copy Markdown
Contributor

Uses ePHPm v0.13.0's multi-key KV functions when they are present. Both are feature-detected with function_exists, and older runtimes keep today's per-key path.

Changes

  • doFetch(): a batch is read with one ephpm_kv_mget call. If the call fails as a whole (false), it falls back to per-key get.
  • doSave(): each batch is written with one ephpm_kv_mset call. AbstractAdapter groups doSave() calls by lifetime, so a single TTL per batch is exact. mset only reports overall success or failure, so if it is refused (memory limit) the batch is retried key by key. That keeps the exact list of failed ids doSave() must return; re-writing keys that already landed is harmless.
  • doClear() is unchanged. It never scanned, so per the brief it stays as it is. The comment, class docblock and README now explain why ephpm_kv_scan is not used for a namespaced clear: in a cluster it lists only the local node's keyspace, and string values above small_key_threshold live only on their replica nodes. A scan-and-delete could report success while stale entries survive on other nodes.
  • Backends: a backend opts in through the new ExtendedKvOpsInterface. Custom KvOpsInterface backends (e.g. the existing FailingSetKvOps test double) still work and take the per-key path.
  • Test fake: InMemoryKvOps implements mget/mset. new InMemoryKvOps([]) behaves like an older runtime.
  • Not changed: values are not moved into hashes.

Tests

  • New MultiKeyOpsTest uses a recording spy to cover: one mget for getItems(), the fallbacks without mget and on a failing mget, one mset per commit with the batch TTL, no-expiry saves, a refused mset falling back to per-key set, and the fallback without mset.
  • SapiKvOpsTest adds stubs and cases for supports(), mget and mset.
  • Ran locally with PHP 8.5.4 and PHPUnit 11.5: 39 tests OK.

doFetch() reads a batch with one ephpm_kv_mget call and doSave() writes
each same-lifetime batch with one ephpm_kv_mset call; a refused mset is
retried key by key so the exact failed ids are still reported. Both are
feature-detected (older runtimes keep the per-key loop). doClear() is
unchanged: ephpm_kv_scan is not cluster-complete, so a namespaced clear
still returns false; the reason is documented.
@luthermonson
luthermonson merged commit 180cb2f into main Oct 22, 2026
3 checks passed
@luthermonson
luthermonson deleted the feat/kv-v013 branch October 22, 2026 10:02
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