Skip to content

feat(setresp): notify host on redis.setresp() via onSetResp hook - #24

Merged
fatal10110 merged 1 commit into
mainfrom
feat/setresp-host-notify
Jun 30, 2026
Merged

feat(setresp): notify host on redis.setresp() via onSetResp hook#24
fatal10110 merged 1 commit into
mainfrom
feat/setresp-host-notify

Conversation

@fatal10110

Copy link
Copy Markdown
Owner

Summary

Lets the host observe redis.setresp(n) without taking ownership of the RESP-mode flip.

redis.setresp must stay a WASM builtin: it mutates g_resp_version, the C global the reply encoder reads, and the host has no handle on that state. So this wraps, not delegatesl_redis_setresp flips the encoder mode (as before) and then calls a new host_redis_setresp(version) import. The engine surfaces it as an optional RedisHost.onSetResp(version) hook the host can use to match the reply shapes it returns from redisCall/redisPcall to the active protocol.

Push-on-change (fires only when setresp runs), not pull-per-call. Absent hook → no-op, so existing hosts are unaffected.

Builds on the RESP3 work merged in #22.

Changes

  • wasm/include/abi.h, wasm/src/redis_api.c: new host_redis_setresp import; l_redis_setresp notifies after the flip.
  • src/engine.ts: wire host_redis_setresp import to the onSetResp handler (default no-op).
  • src/types.ts: optional RedisHost.onSetResp?: (version: 2 | 3) => void.
  • test/engine.test.ts: host receives [3, 2] on two setresp calls; missing hook is a no-op.
  • docs/host-interface.md: document the hook.

Validation

  • WASM rebuilt (Docker/Emscripten).
  • node --test --import tsx test/**/*.test.ts: 181/181 passing.

🤖 Generated with Claude Code

The WASM encoder owns the RESP-mode flip (g_resp_version drives reply
encoding and cannot be host-set). To let the host mirror the protocol
when choosing reply shapes for redisCall/redisPcall, l_redis_setresp now
calls a new host_redis_setresp(version) import after flipping. The engine
exposes this as an optional RedisHost.onSetResp(version) hook; absent, it
is a no-op so existing hosts are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@fatal10110
fatal10110 merged commit b265ab4 into main Jun 30, 2026
5 checks passed
@fatal10110
fatal10110 deleted the feat/setresp-host-notify branch June 30, 2026 11:15
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