Skip to content

fix(rueidiscompat): drop the txt: prefix from Info and ClientList - #1051

Open
LindseyZ1205 wants to merge 1 commit into
redis:mainfrom
LindseyZ1205:fix/compat-verbatim-txt-prefix
Open

LindseyZ1205 wants to merge 1 commit into
redis:mainfrom
LindseyZ1205:fix/compat-verbatim-txt-prefix

Conversation

@LindseyZ1205

@LindseyZ1205 LindseyZ1205 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

With RESP3, which rueidis uses by default, Info, ClientList, ClusterInfo and ClusterNodes return values that start with txt::

adapter := rueidiscompat.NewAdapter(client)

adapter.Info(ctx).Val()       // "txt:# Server\r\nredis_version:8.2.1\r\n..."
adapter.ClientList(ctx).Val() // "txt:id=4 addr=127.0.0.1:52416 ..."
// go-redis, and rueidiscompat with RESP2: "# Server\r\n...", "id=4 addr=..."

With RESP3, these four commands reply with a verbatim string, whose first four bytes are its format (txt:). ToString() returns the whole string, and these methods used newStringCmd, so the format ended up in the value. The first line of INFO is txt:# Server instead of a section header, the first client in CLIENT LIST has a txt:id field, and the first node ID in CLUSTER NODES starts with txt:. go-redis drops the format, and ClientInfo and InfoMap already trim it in their parsers.

This change adds newTxtStringCmd, which trims the txt: prefix in StringCmd.from, and uses it for these four commands. The flag is on the StringCmd, so the prefix is also trimmed when a pipeline fills in the result. RESP2 replies don't have the prefix and are unchanged, and so are the other commands that use newStringCmd.

Tests

  • The should Info, should Info cpu, should ClientList, ClusterInfo and ClusterNodes specs only checked that the values weren't empty, so they passed with the prefix. They now check how the values start (# Server, # CPU, id=, cluster_state:, and a node ID on each line of CLUSTER NODES). A new should Pipeline Info and ClientList spec does the same through a pipeline. I ran the adapter suite against local Redis 8.2.1 servers on the docker-compose.yml ports: these specs fail without this change and pass with it, and they are the only difference this change makes in the suite. The other failures there need the modules or the Redis 8.4+ commands that my local servers don't have. Locally the RESP2 clients also negotiated RESP3, because the RESP2 server is Redis 5 in CI, so I checked RESP2 separately (third item).
  • New TestTxtStringCmdFrom in command_test.go. The mock package has no verbatim string, so it uses blob strings with and without the prefix.
  • I also compared Info, ClientList, ClusterInfo and ClusterNodes with go-redis against a local Redis 8.2.1 and a local cluster, with and without AlwaysRESP2, and Info and ClientList through a pipeline. Without this change the RESP3 values start with txt:. With it they start the same way as go-redis's, and the RESP2 values are the same as before.
  • The rueidiscompat tests that don't need a server (go test -skip '^TestAdapter$') pass, and gofmt and go vet report nothing.

Note

Low Risk
Localized string normalization for four admin/cluster commands; RESP2 and other newStringCmd callers are unchanged.

Overview
Under RESP3, Info, ClientList, ClusterInfo, and ClusterNodes were returning values prefixed with txt: because verbatim replies include that format tag in ToString(). That broke parity with go-redis and RESP2 (e.g. # Server vs txt:# Server).

This PR introduces newTxtStringCmd, which sets a flag on StringCmd so from strips a leading txt: when present, and wires those four adapter methods to use it instead of newStringCmd. Pipelines keep the same behavior because the flag lives on the command object filled when results arrive.

Tests now assert realistic value prefixes, add TestTxtStringCmdFrom, and cover pipelined Info / ClientList.

Reviewed by Cursor Bugbot for commit 4c001be. Bugbot is set up for automated code reviews on this repo. Configure here.

With RESP3, INFO, CLIENT LIST, CLUSTER INFO and CLUSTER NODES reply with
a verbatim string, which starts with its "txt:" format. Info, ClientList,
ClusterInfo and ClusterNodes returned it as is, so their values started
with "txt:" with RESP3 but not with RESP2, and the first line didn't
parse. go-redis drops the format, and ClientInfo and InfoMap already
trim it here. Trim it in these four commands as well, including in
pipelines.
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