Repository navigation
Implement connection-local CLIENT REPLY - #211
Conversation
Add Redis-compatible ON, OFF, and SKIP reply handling across pipelines, transactions, and subscribed clients. Cover exact RESP bytes and errors in integration tests; update command metadata and compatibility docs. Tested with: make check; cargo build --release; Redis 8.10.2 raw-socket comparison.
|
Thanks for this PR. While I reviewed it against Redis 8.10.2, I found one behavior gap and have a tested fix. Bug:
|
| Pipeline | Redis 8.10.2 | PR #211 now |
|---|---|---|
CLIENT REPLY OFF, CLIENT REPLY SKIP, SET k v, GET k |
(nothing) | $1\r\nv\r\n |
CLIENT REPLY OFF, CLIENT REPLY SKIP, PING, PING, CLIENT REPLY ON, PING |
+OK\r\n+PONG\r\n |
+PONG\r\n+OK\r\n+PONG\r\n |
CLIENT REPLY OFF, CLIENT REPLY SKIP, RESET, PING |
+RESET\r\n+PONG\r\n |
+PONG\r\n |
MULTI, CLIENT REPLY OFF, CLIENT REPLY SKIP, PING, EXEC, PING |
...+QUEUED\r\n*3\r\n |
...+QUEUED\r\n*3\r\n+PONG\r\n |
With the patch below, all 11 probe pipelines I tried give byte-identical output to Redis 8.10.2. These include the four above and the cases this PR already covers: SKIP→ON, SKIP→SKIP, SKIP→OFF, MULTI with SKIP, OFF→MULTI→ON→EXEC, and a lowercase skip.
Patch
One guard in the SKIP arm, a regression test (fails before the fix, passes after), and one sentence in docs/COMPATIBILITY.md:
diff --git a/docs/COMPATIBILITY.md b/docs/COMPATIBILITY.md
index 865fb47..1bff9c5 100644
--- a/docs/COMPATIBILITY.md
+++ b/docs/COMPATIBILITY.md
@@ -554,6 +554,7 @@ remain pending. Metadata is local to the connection and is never persisted.
`CLIENT REPLY ON|OFF|SKIP` controls command replies per connection. `OFF` and
`SKIP` produce no reply themselves; `ON` replies `+OK`. `SKIP` suppresses the
next command reply, including an error; `ON` can restore replies immediately.
+`SKIP` has no effect while replies are `OFF`.
`RESET` restores reply mode while respecting a pending `SKIP`. Subscription
acknowledgements and published messages remain visible in subscribed mode,
matching Redis even when ordinary command replies are disabled.
diff --git a/src/connection.rs b/src/connection.rs
index 6956414..3777c9b 100644
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -155,7 +155,11 @@ impl Session {
b"REPLY" => match c[2].to_ascii_uppercase().as_slice() {
b"ON" => { self.reply_mode = ReplyMode::On; b"+OK\r\n".to_vec() }
b"OFF" => { self.reply_mode = ReplyMode::Off; b"+OK\r\n".to_vec() }
- b"SKIP" => { self.reply_mode = ReplyMode::Skip; b"+OK\r\n".to_vec() }
+ b"SKIP" => {
+ // Redis ignores SKIP while replies are OFF.
+ if self.reply_mode != ReplyMode::Off { self.reply_mode = ReplyMode::Skip; }
+ b"+OK\r\n".to_vec()
+ }
_ => protocol::error("syntax error"),
},
b"INFO" => protocol::bulk(format!(
diff --git a/tests/client_reply.rs b/tests/client_reply.rs
index 26c274b..834d304 100644
--- a/tests/client_reply.rs
+++ b/tests/client_reply.rs
@@ -270,3 +270,34 @@ fn subscribed_acknowledgements_and_messages_bypass_reply_off() {
b"*3\r\n$7\r\nmessage\r\n$13\r\nreply:channel\r\n$7\r\nmessage\r\n"
);
}
+
+#[test]
+fn skip_is_ignored_while_replies_are_off() {
+ let server = Server::start();
+ assert_eq!(
+ exchange(
+ &server,
+ &[
+ &["CLIENT", "REPLY", "OFF"],
+ &["CLIENT", "REPLY", "SKIP"],
+ &["SET", "reply:skip-off", "v"],
+ &["GET", "reply:skip-off"],
+ &["CLIENT", "REPLY", "ON"],
+ &["GET", "reply:skip-off"]
+ ]
+ ),
+ b"+OK\r\n$1\r\nv\r\n"
+ );
+ assert_eq!(
+ exchange(
+ &server,
+ &[
+ &["CLIENT", "REPLY", "OFF"],
+ &["CLIENT", "REPLY", "SKIP"],
+ &["RESET"],
+ &["PING"]
+ ]
+ ),
+ b"+RESET\r\n+PONG\r\n"
+ );
+}Test results (on this branch with the patch)
make check(fmt,clippy -D warnings,cargo test): pass, 41 test binaries ok, 0 failed.cargo build --release: pass.- New test
skip_is_ignored_while_replies_are_off: fails without the fix, passes with it. - Note:
tests/protocol_limits.rsfailed once under a heavy parallel load on my machine. It passed in 3 isolated reruns and in the next fullmake check. This PR does not touch it.
Request: follow-up commit with co-author credit
@mansiverma897993, could you apply this patch as a follow-up commit on this branch (please keep your original commit; no rewrite or squash):
- Author and committer:
Mansi Verma <vmansi756@gmail.com> - Final line of the commit message, after a blank line:
Co-authored-by: Mohit Goyal <goel0632@gmail.com> - No tool or AI attribution lines.
Example: git apply client-reply-skip-off.patch && git commit -am "fix: ignore CLIENT REPLY SKIP while replies are OFF" -m "Co-authored-by: Mohit Goyal <goel0632@gmail.com>"
Conflict to note: AGENTS.md ("Do not") says not to add Co-authored-by trailers to commits. I read that rule as being about tool/AI attribution for agents. This trailer is for a human collaborator, which you asked for. You are the maintainer, so the choice is yours. If you prefer to keep the rule strict, apply the patch without the trailer; the fix is still worth having.
After you push, I will check the commit metadata, make check, cargo build --release, and all CI checks, then merge with a merge commit (not a squash) so the trailer stays, if you want me to.
Preserve OFF mode when SKIP follows it. Cover suppressed writes, reset and transactions with exact RESP regression tests, and document the behavior. Tested with: make check; cargo build --release; Redis 8.10.2 raw-socket comparison. Co-authored-by: Mohit Goyal <goel0632@gmail.com>
Summary
Implements connection-local
CLIENT REPLY ON|OFF|SKIP, including Redis-compatible reply timing across pipelines, transactions, subscribed clients, andRESET. Adds command metadata and compatibility notes.Closes #208. Reference: Redis CLIENT REPLY.
Testing
make check— passed (format, clippy, full test suite).cargo build --release— passed.Compatibility
No known difference for the tested RESP2 cases. Redis's partial
EXECarray bytes when a queued reply-mode change suppresses elements are preserved.