method

RedisClient.subscribe

channel: string,
): Promise<number>;

Subscribe to a Redis channel.

Subscribing disables automatic pipelining, so all commands are 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() can be called while subscribed.

@param channel

The channel to subscribe to.

@param listener

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

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 are 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 receives the message as the first argument and the channel as the second.

Referenced types

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