Msubscribe
Bun

method

RedisClient.subscribe

channel: string,
): Promise<number>;

Subscribe to a Redis channel.

Subscribing disables automatic pipelining, so all commands will be received immediately.

Subscribing moves the channel to a dedicated subscription state which prevents most other commands from being executed until unsubscribed. Only .ping(), .subscribe(), and .unsubscribe() are legal to invoke in a subscribed upon channel.

@param channel

The channel to subscribe to.

@param listener

The listener to call when a message is received on the channel. The listener will receive the message as the first argument and the channel as the second argument.

await client.subscribe("my-channel", (message, channel) => {
  console.log(`Received message on ${channel}: ${message}`);
});
channels: string[],
): Promise<number>;

Subscribe to multiple Redis channels.

Subscribing disables automatic pipelining, so all commands will be received immediately.

Subscribing moves the channels to a dedicated subscription state in which only a limited set of commands can be executed.

@param channels

An array of channels to subscribe to.

@param listener

The listener to call when a message is received on any of the subscribed channels. The listener will receive the message as the first argument and the channel as the second argument.

Referenced types

type StringPubSubListener = (message: string, channel: string) => void