method
RedisClient.subscribe
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.
The channel to subscribe to.
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}`);
});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.
An array of channels to subscribe to.
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.