Implement CLIENT REPLY ON|OFF|SKIP (#1626)
Fixes #1626
Summary
Implements CLIENT REPLY ON|OFF|SKIP matching Redis semantics:
- ON (default): replies sent normally.
- OFF: all replies suppressed until next
CLIENT REPLY ON. - SKIP: one-shot — suppresses the reply of the next non-
CLIENT REPLYcommand (including unknown / parse-error commands), then auto-returns toON.
Per Redis behavior, CLIENT REPLY OFF and CLIENT REPLY SKIP themselves return no reply; CLIENT REPLY ON returns +OK.
Implementation
Per-session state lives on RespServerSession:
clientReplyMode(On/Off/Skip)suppressCurrentReply(per-iteration flag)cmdReplyFloor(snapshot ofdcurrat the start of the current command — the rewind floor under suppression so prior queued replies in the same batch are preserved)
In ProcessMessages, before ParseCommand, we snapshot modeAtStart and cmdReplyFloor = dcurr, then set suppressCurrentReply = (modeAtStart != On). This ensures parse-time errors (e.g. malformed / unknown command) are also gated.
SendAndReset() (suppression path):
- If the suppressed write made progress (
dcurr > cmdReplyFloor): rewind tocmdReplyFloor— keeps[head, cmdReplyFloor)intact. - Else if prior replies are queued (
cmdReplyFloor > head): flush[head, cmdReplyFloor), rotate buffer, setcmdReplyFloor = new head. Suppression continues in the fresh buffer. - Else (no prior bytes, no progress): throw — same fatal "buffer too small" condition as the non-suppressed path. Prevents the infinite-loop scenario where a suppressed reply is larger than the entire response buffer.
SendAndReset(IMemoryOwner<byte>, int) (suppression path): drop the payload outright (do not flush the buffer, which may contain this command's earlier bytes between cmdReplyFloor and dcurr).
End-of-command: if still flagged, dcurr = cmdReplyFloor rewinds the accumulated reply. CLIENT REPLY ON clears the flag inside its own handler so its +OK survives. After dispatch, if mode was Skip and the command wasn't CLIENT REPLY, mode auto-resets to On — this fires for unknown / INVALID commands too, matching Redis.
Files
| File | Change |
|---|---|
libs/server/Resp/Parser/RespCommand.cs |
CLIENT_REPLY enum + parser case + AofIndependentCommands entry |
libs/server/Resp/ClientCommands.cs |
ClientReplyMode enum + NetworkCLIENTREPLY handler |
libs/server/Resp/RespServerSession.cs |
Per-session state + floor, snapshot/rewind hook in ProcessMessages, suppression-aware SendAndReset overloads |
libs/server/Resp/CmdStrings.cs |
REPLY / SKIP u8 constants |
libs/resources/RespCommandsInfo.json, RespCommandsDocs.json |
CLIENT|REPLY metadata |
playground/CommandInfoUpdater/SupportedCommand.cs |
Subcommand registration |
test/Garnet.test/RespCommandTests.cs |
Added CLIENT_REPLY to AofIndependent list |
test/Garnet.test/ClientReplyTests.cs (new) |
12 raw-TCP NUnit tests |
Testing
- Build: 0 warnings, 0 errors.
- New
ClientReplyTests: 12/12 pass on bothnet8.0andnet10.0. Coverage:ClientReplyOnReturnsOK—ONreturns+OK.ClientReplyOffSuppressesResponses— OFF gates PING/SET/GET; ON resumes.ClientReplySkipSuppressesOnlyNextCommand— SKIP is one-shot.ClientReplyWrongArityReturnsError— wrong arity returns-ERR…(uses CRLF-awareReadSimpleReply).ClientReplyInvalidModeReturnsSyntaxError— unknown mode returns-ERR syntax error.ClientReplyCaseInsensitive— lower/mixed case modes accepted.ClientReplyOffPersistsAcrossManyCommands— 50 SETs under OFF, all execute, no reply bytes; verified out-of-band via a second connection.ClientReplyOffErrorAlsoSuppressed— error replies (parse + syntax) are suppressed under OFF.ClientReplySkipDoesNotStack— two consecutive SKIPs only suppress one following command.ClientReplySkipBurnedByUnknownCommand— SKIP followed by unknown command suppresses the error AND burns the SKIP (next command replies normally).ClientReplyPipelinedSkipBetweenReplies—PING / SKIP / PING / PINGpipelined in a single TCP write yields exactly two+PONGreplies. Verifies the prior reply isn't lost by the in-batch suppression rewind.ClientReplyPipelinedOffOnOrdering—PING / OFF / PING / ONpipelined yields+PONG +OKin order.
RespCommandTestsclass: 49/49 pass (incl.AofIndependentCommandsTestand command info/docs metadata).- Broader
~Clientfilter: 130/131 — single failure (RespRangeIndexTests.RIConcurrentMultiClientTest) reproduces on a clean tree, pre-existing flake unrelated to this change.
Known limitation
Inside MULTI/EXEC, CLIENT REPLY queues through the existing NetworkSKIP path and takes effect at EXEC replay time. This matches Redis semantics for v1.
Pub/sub interaction is not specifically tested in this PR — CLIENT REPLY is gated at the generic response buffer layer, so it applies uniformly to all reply types, but a targeted pub/sub test could be added in a follow-up.