Skip to main content

Module reply

Module reply 

Source
Expand description

Replies out: wire bytes, written once.

This is Y18 and it is a locked decision rather than a preference. A reply is built directly as the bytes that go on the socket. There is no intermediate value, no enum to match on later, no boxed trait object, and no second pass that turns a structure into bytes. Redis 8.8 gained forty percent on SCAN by fixing exactly this in its own reply path, which is the best available evidence that the shape matters more than the constant factors inside it.

The other half of Y18 is presizing. A reply whose size is known should reserve once, before the first byte, from whichever side of the operation is smaller. Out::reserve and the *_len helpers are there so that a command can do that arithmetic without writing anything twice.

§The protocol lives here

A command writes a map. Whether that map goes out as RESP3’s % or as RESP2’s flattened array is this module’s problem and not the command’s. Every command in the engine is written once, against the richer protocol, and the downgrade happens in one place where it can be tested. The alternative is a protocol check in three hundred command implementations, and the failure mode of that is a command that works on one protocol and not the other.

Structs§

Out
A reply buffer for one connection.