Skip to content

v4 design: generated scripts and functions - #3401

Merged
mgravell merged 5 commits into
v4from
marc/v4-generated-scripts
Dec 3, 2026
Merged

mgravell merged 5 commits into
v4from
marc/v4-generated-scripts

Conversation

@mgravell

@mgravell mgravell commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

An exploratory design for the idea from #3364: declare a script or function as a partial method, and have the generator write the call. It's a design note only, with no code, following the "ideas, not decisions" convention of design/.

What it proposes:

  • Two layers. Binding is shared: the signature, key/arg split, reply handler, and a method body that renders <call> <id> numkeys keys... args.... The kind decides the call command and what happens when the server doesn't have the code.

  • Scripts: a Lua body with parameters bound by name (@key, @count), rewritten at build time so the hash is a constant. The client provisions on demand as it does today (SCRIPT LOAD paired with EVALSHA). The NOSCRIPT repair works from the sent frame, which relies on v4 Scripts: build the NOSCRIPT retry from the rendered EVALSHA, not the caller's spans #3398, so generated code never holds argument arrays.

  • Functions are opaque names. A [RedisFunction("name", ReadOnly = ...)] declaration has no body and binds positionally. It sends FCALL/FCALL_RO, and ERR Function not found is reported, never repaired. Loading is a deployment concern. FUNCTION LOAD and the other administration commands go on IServer, outside the execution pipeline, which also settles the deferred FUNCTION * rows in the coverage ledger (Missing Commands in StackExchange.Redis #2055).

  • The general case (§9). The marc/respite spike's RespCommandGenerator declared every command as a partial method ([RespCommand], [RespPrefix] for literals and counts, [RespIgnore] for optional clauses). The proposal is to retarget that model at v4's builder, make it public for ad-hoc and module commands, and build scripts and functions as specialisations of it. It isn't proposed as a replacement for v4's hand-written methods, which are already one-liners.

Open questions are in §11. Mainly: the public runtime surface the generated code calls, variable-length key and argument lists, and the shape of the IServer administration API. §12 has a suggested order of work.

A shape for declaring server-side code as partial methods: binding by name, shared call shape, per-kind provisioning; facts checked against Redis 8.12.
@mgravell
mgravell marked this pull request as ready for review December 3, 2026 15:03
@mgravell
mgravell merged commit d6203e7 into v4 Dec 3, 2026
2 of 3 checks passed
@mgravell
mgravell deleted the marc/v4-generated-scripts branch December 3, 2026 15:03
pairbit added a commit to pairbit/IT.Redis that referenced this pull request Dec 3, 2026
* v4 design: generated scripts and functions (seredis#3401)

* design: generated scripts and functions (exploratory)

A shape for declaring server-side code as partial methods: binding by name, shared call shape, per-kind provisioning; facts checked against Redis 8.12.

* design: functions are opaque names; administration on IServer, not in the pipeline

* design: lists of keys and arguments, and how a script sees them

* design: the general case - declared commands, after the marc/respite RespCommandGenerator

* design: keyword clauses (prefix, suffix, count, ignore-when) as the core of the declared-command model

* v4: Redis 8.12 test topology (cluster bus protected mode, ZSCAN duplicates), from main's seredis#3343 (seredis#3399)

* CI (Windows): let Redis 8.12 start the cluster nodes

8.12 refuses a cluster node with an unauthenticated bus port unless cluster-bus-port-protected-mode is off; older servers reject the option, so it is passed only to 8.12 and later.

* Redis 8.12 test topology, ported from main's seredis#3343: cluster-bus-port-protected-mode in the cluster confs, client-libs-test:8.12.0, and ZSCAN may return duplicates

Replaces the version-gated CI.yml option: main already solves this in the cluster confs, and v4 follows it.

* v4 Scripts: build the NOSCRIPT retry from the rendered EVALSHA, not the caller's spans (seredis#3398)

* Scripts: build the NOSCRIPT retry from the rendered EVALSHA, not the caller's spans

The repair captured keys/args with ToArray() whenever the send had not completed synchronously. That copied the RedisValues but not the memory under them, so a caller who returned a pooled buffer after the call returned had the retry send whatever was there by the time NOSCRIPT arrived; and it cost two arrays on almost every real call.

The retry now holds a reference to the rendered EVALSHA (a reference count, no copy) and re-renders EVAL from its arguments through the command map, without re-applying the key prefix the keys already carry.

* SendWithPreambleAsync: the gate and cancellation token are required, not defaulted

Internal, so correctness wins over convenience: a caller that forgets to pass its token should not compile.

---------

Co-authored-by: Marc Gravell <marc.gravell@gmail.com>
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