Skip to content

feat(microservices): add return buffers option for binary data#16676

Open
Forceres wants to merge 2 commits intonestjs:masterfrom
Forceres:feat/client-redis-binary-format
Open

feat(microservices): add return buffers option for binary data#16676
Forceres wants to merge 2 commits intonestjs:masterfrom
Forceres:feat/client-redis-binary-format

Conversation

@Forceres
Copy link
Copy Markdown

@Forceres Forceres commented Apr 1, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Now we can't directly get buffers from redis, so any custom binary formats are broken. Moreover, our redis output has to be json that contradicts to custom binary formats.

What is the new behavior?

We can pass returnBuffers to client options for listening on "messageBuffer" instead of "message" to get directly buffers from redis. createResponseCallback handles jsons as well as binary (but we have to pass custom deserializer to decode id from it)

Does this PR introduce a breaking change?

  • Yes
  • No

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 1, 2026

Pull Request Test Coverage Report for Build 472dd428-2ae6-4d12-bfd5-a48cbbd1c630

Details

  • 6 of 9 (66.67%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.03%) to 89.828%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/microservices/client/client-redis.ts 6 9 66.67%
Files with Coverage Reduction New Missed Lines %
packages/microservices/client/client-redis.ts 1 79.39%
Totals Coverage Status
Change from base Build bcb7b573-9798-42cb-a347-1d1f9e70592c: -0.03%
Covered Lines: 7603
Relevant Lines: 8464

💛 - Coveralls

@kamilmysliwiec
Copy link
Copy Markdown
Member

Could you please add an integration test for this as well?

@Forceres
Copy link
Copy Markdown
Author

Forceres commented Apr 3, 2026

Could you please add an integration test for this as well?

Yeah, give me some time.

@Qodo-Free-For-OSS
Copy link
Copy Markdown

Hi, returnBuffers is used as a client option but it is not part of the public RedisOptions / IORedisOptions types, so TypeScript consumers cannot set it without type assertions and won’t discover it via IntelliSense.

Severity: action required | Category: maintainability

How to fix: Add returnBuffers to options types

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

returnBuffers is implemented/used but is not part of the public Redis options typings, so TS users can’t set it cleanly.

Issue Context

RedisOptions.options is ... & IORedisOptions, but IORedisOptions doesn’t include returnBuffers.

Fix Focus Areas

  • packages/microservices/external/redis.interface.ts[1-120]
  • packages/microservices/interfaces/microservice-configuration.interface.ts[123-137]

Notes

Prefer adding returnBuffers?: boolean to IORedisOptions (since it’s an ioredis option) so it flows through RedisOptions everywhere.

We noticed a couple of other issues in this PR as well - happy to share if helpful.


Spotted by Qodo code review - free for open-source projects.

@Qodo-Free-For-OSS
Copy link
Copy Markdown

Hi, When returnBuffers is enabled, the Redis subscription handler is attached to messageBuffer, but createResponseCallback() is still typed as receiving buffer: string, reducing type-safety and encouraging incorrect usage.

Severity: remediation recommended | Category: maintainability

How to fix: Widen callback param type

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

createResponseCallback() should accept both string and Buffer payloads because it can be bound to either message or messageBuffer.

Issue Context

When returnBuffers is true, registerReadyListener binds messageBuffer.

Fix Focus Areas

  • packages/microservices/client/client-redis.ts[138-155]
  • packages/microservices/client/client-redis.ts[231-270]

Notes

Update the signature to (channel: string, buffer: string | Buffer) => Promise<void> and adjust parsing to avoid implicit coercions (e.g., const raw = Buffer.isBuffer(buffer) ? buffer.toString() : buffer).

We noticed a couple of other issues in this PR as well - happy to share if helpful.


Found by Qodo code review

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.

4 participants