feat(setresp): notify host on redis.setresp() via onSetResp hook - #24
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lets the host observe
redis.setresp(n)without taking ownership of the RESP-mode flip.redis.setrespmust stay a WASM builtin: it mutatesg_resp_version, the C global the reply encoder reads, and the host has no handle on that state. So this wraps, not delegates —l_redis_setrespflips the encoder mode (as before) and then calls a newhost_redis_setresp(version)import. The engine surfaces it as an optionalRedisHost.onSetResp(version)hook the host can use to match the reply shapes it returns fromredisCall/redisPcallto the active protocol.Push-on-change (fires only when
setrespruns), 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: newhost_redis_setrespimport;l_redis_setrespnotifies after the flip.src/engine.ts: wirehost_redis_setrespimport to theonSetResphandler (default no-op).src/types.ts: optionalRedisHost.onSetResp?: (version: 2 | 3) => void.test/engine.test.ts: host receives[3, 2]on twosetrespcalls; missing hook is a no-op.docs/host-interface.md: document the hook.Validation
node --test --import tsx test/**/*.test.ts: 181/181 passing.🤖 Generated with Claude Code