Skip to content

fix(client): keep binary stream names in RESP3 XREAD replies - #3540

Merged
nkaradzhov merged 1 commit into
redis:masterfrom
Tanishq-Choudhary:xread-resp3-buffer-stream-names
Oct 27, 2026
Merged

nkaradzhov merged 1 commit into
redis:masterfrom
Tanishq-Choudhary:xread-resp3-buffer-stream-names

Conversation

@Tanishq-Choudhary

@Tanishq-Choudhary Tanishq-Choudhary commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

On RESP3, xRead and xReadGroup turn a binary stream name into a lossy UTF-8 string, even with the type mapping that docs/RESP.md suggests for keeping map keys as Buffers ("decode them as Arrays instead"):

const key = Buffer.from([0x73, 0xff, 0xfe]);
await client.xAdd(key, '1-0', { field: 'value' });

const [{ name }] = await client
  .withTypeMapping({ [RESP_TYPES.BLOB_STRING]: Buffer, [RESP_TYPES.MAP]: Array })
  .xRead({ key, id: '0' });

await client.xRange(name, '-', '+');

On master against Redis 8.9, RESP2 gives name as <Buffer 73 ff fe> and xRange returns the entry. RESP3 gives name as the string 's��' and xRange returns [].

With MAP: Array the decoder hands the name over as a Buffer, and transformStreamsMessagesReplyResp3Compat then calls toString() on it. This returns the name as decoded, like the RESP2 transform does. Without a Buffer mapping the name is already a string, so default replies are unchanged.

Added a transformReply test with a non-UTF-8 name; it fails on master with name: 'k��'. I ran the @redis/client suite in a Linux container with the Redis 8.9 image from the test config: 3415 passing, and the same 19 sentinel and socket timeout failures as on master in that setup. Lint is clean on the changed files. I did not run the other workspaces.


Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Note

Low Risk
Narrow change to RESP3 XREAD/XREADGROUP reply shaping; only affects stream name when MAP is decoded as Array and blob strings may be Buffers.

Overview
Fixes RESP3 xRead / xReadGroup so stream name values are not forced through toString() when the reply is normalized from a map-as-Array shape.

In transformStreamsMessagesReplyResp3Compat, the array branch now assigns name: rawName instead of coercing with rawName?.toString?.(). With withTypeMapping({ [RESP_TYPES.BLOB_STRING]: Buffer, [RESP_TYPES.MAP]: Array }), non-UTF-8 stream keys stay Buffer (matching RESP2), so follow-up commands like xRange use the correct key. Default mappings (string names) are unchanged.

Adds a unit test on XREAD.transformReply[3] with a binary stream name and the Buffer/Array type mapping.

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

With RESP3 and a type mapping of { [RESP_TYPES.BLOB_STRING]: Buffer,
[RESP_TYPES.MAP]: Array }, xRead and xReadGroup returned each stream
name as a string decoded from UTF-8, so non-UTF-8 key bytes were
replaced with U+FFFD and the name could not be used to address the
stream again. RESP2 returns the Buffer. Return the name as decoded.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T15:46:37.074482Z 452aa8f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@nkaradzhov nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM.

@nkaradzhov
nkaradzhov merged commit e3c20f0 into redis:master Oct 27, 2026
15 checks passed
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.

2 participants