This class is used to publish on a prefixed channel using the Redis PubSub.
export interface ChannelOptions {
name: string;
prefix?: string;
}
export type MessageWithMetadata<T, K> = T & {
metadata: K;
};
export type PublishOptions<
T extends Record<string, any> = Record<string, any>,
K extends Record<string, any> | null = null> = K extends Record<string, any> ?
(MessageWithMetadata<T, K> | MessageWithMetadata<T, K>[]) : (T | T[]);
import { Channel } from "@myunisoft/redis";
const name = "foo";
const subscriber = await initRedis(options, true);
await subscriber.subscribe(name);
subscriber.on("message", (channel, message) => {
// Handle incoming event
});
const channel = new Channel({ name });
Publish an event on the pubsub channel
await channel.publish({ data: { foo: "bar" }});