Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubSub with binary messages #335

Closed
darrachequesne opened this issue Sep 28, 2022 · 1 comment · Fixed by #354
Closed

PubSub with binary messages #335

darrachequesne opened this issue Sep 28, 2022 · 1 comment · Fixed by #354
Labels
enhancement New feature or request

Comments

@darrachequesne
Copy link
Contributor

darrachequesne commented Sep 28, 2022

Hi!

Is there a way to put a subscription in binary mode?

import { connect } from "https://deno.land/x/redis@v0.27.0/mod.ts";

const pubClient = await connect({ hostname: "localhost" });
const subClient = await connect({ hostname: "localhost" });

subClient.subscribe("channel").then(async (sub) => {
    for await (const { message } of sub.receive()) {
        console.log(message); // prints "e�"
    }
});

setTimeout(() => {
    pubClient.publish("channel", Uint8Array.from([1, 101, 201]));
}, 200);

Node.js with redis:

import { createClient } from "redis";

const pubClient = createClient({ url: "redis://localhost:6379" });
const subClient = pubClient.duplicate();

await Promise.all([pubClient.connect(), subClient.connect()]);

await subClient.subscribe("channel", (message) => {
    console.log(message); // prints "<Buffer 01 65 c9>"
}, true);

await pubClient.publish("channel", Buffer.from([1, 101, 201]));

Update: I don't think this is currently possible, as the response from the server is decoded with a TextDecoder:

redis/protocol/reply.ts

Lines 106 to 108 in 878c883

override bulk() {
return this.#body ? decoder.decode(this.#body) : null;
}

redis/protocol/reply.ts

Lines 243 to 246 in 878c883

case BulkReplyCode: {
const reply = await BulkReply.decode(reader);
array.push(reply.bulk());
break;

darrachequesne added a commit to socketio/socket.io-deno that referenced this issue Oct 4, 2022
In order to provide a temporary workaround for [1].

[1]: denodrivers/redis#335
darrachequesne added a commit to socketio/socket.io-deno that referenced this issue Oct 4, 2022
We had to make a few changes to the redis module (in the vendor/
directory), in order to implement the feature. We will remove it once
the changes are merged upstream.

See also: denodrivers/redis#335

This implementation is compatible with the Node.js one (same format for
the Redis channels and the packets).

See also: https://github.com/socketio/socket.io-redis-adapter
@uki00a uki00a added the enhancement New feature or request label Oct 17, 2022
@uki00a
Copy link
Member

uki00a commented Oct 17, 2022

@darrachequesne Hi, sorry for the late response.

deno-redis currently doesn't support PubSub with binary messages. However, I'll consider supporting this as it would be useful 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants