Skip to content

Pub/sub with binary in v4 #1718

@darrachequesne

Description

@darrachequesne

Hi! Is it possible to send binary content with PUB/SUB in v4?

const { createClient } = require("redis");

(async () => {
  const client = createClient();
  await client.connect();

  const subscriber = client.duplicate();
  await subscriber.connect();

  await subscriber.subscribe("channel", (message, channel) => {
    console.log(Buffer.from(message, "utf8")); // prints "<Buffer ef bf bd ef bf bd ef bf bd>"
  });

  client.publish("channel", Buffer.from([0xa1, 0xa2, 0xa3]));

})();

message is typed as string here:

export type PubSubListener = (message: string, channel: string) => unknown;

And it seems we have no control over the setReturnBuffers() here:

this.#parser.setReturnBuffers(!!this.#waitingForReply.head?.value.bufferMode);

Thanks in advance!

Environment:

  • Node.js Version: v12.9.0
  • Redis Server Version: 5.0.9
  • Node Redis Version: 4.0.0-rc.3
  • Platform: Ubuntu 20.04.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions