PubSubRedisBroker

export declare class PubSubRedisBroker<TEvents extends Record<string, any>> extends BaseRedisBroker<TEvents> implements IPubSubBroker<TEvents>
export declare class PubSubRedisBroker<TEvents extends Record<string, any>> extends BaseRedisBroker<TEvents> implements IPubSubBroker<TEvents>
PubSub broker powered by Redis
Example
// publisher.js
import { PubSubRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new PubSubRedisBroker(new Redis());

await broker.publish('test', 'Hello World!');
await broker.destroy();

// subscriber.js
import { PubSubRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new PubSubRedisBroker(new Redis());
broker.on('test', ({ data, ack }) => {
console.log(data);
void ack();
});

await broker.subscribe('subscribers', ['test']);
// publisher.js
import { PubSubRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new PubSubRedisBroker(new Redis());

await broker.publish('test', 'Hello World!');
await broker.destroy();

// subscriber.js
import { PubSubRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new PubSubRedisBroker(new Redis());
broker.on('test', ({ data, ack }) => {
console.log(data);
void ack();
});

await broker.subscribe('subscribers', ['test']);

Extends

BaseRedisBroker<TEvents>

Implements

IPubSubBroker<TEvents>
NameConstraintsOptionalDefaultDescription
TEventsRecord<string, any>NoNone
Protected
listening:boolean
Whether this broker is currently polling events
Inherited from BaseRedisBroker
ProtectedReadonly
Options this broker is using
Inherited from BaseRedisBroker
ProtectedReadonly
redisClient:Redis
Inherited from BaseRedisBroker
StaticReadonly
STREAM_DATA_KEY:
Used for Redis queues, see the 3rd argument taken by xadd
Inherited from BaseRedisBroker
ProtectedReadonly
streamReadClient:Redis
Internal copy of the Redis client being used to read incoming payloads
Inherited from BaseRedisBroker
ProtectedReadonly
subscribedEvents:Set<string>
Events this broker has subscribed to
Inherited from BaseRedisBroker
destroy():Promise<void>
Destroys the broker, closing all connections
Inherited from BaseRedisBroker
Protected
emitEvent(id, group, event, data):void
NameTypeOptionalDescription
idBufferNoNone
groupstringNoNone
eventstringNoNone
dataunknownNoNone
Protected
listen():Promise<void>
Begins polling for events, firing them to listen
Inherited from BaseRedisBroker
publish(event, data):Promise<void>
Publishes an event
NameTypeOptionalDescription
eventEventNoNone
dataTEvents[Event]NoNone
subscribe(events):Promise<void>
Subscribes to the given events
NameTypeOptionalDescription
events(keyof TEvents)[]NoNone
Inherited from BaseRedisBroker
unsubscribe(events):Promise<void>
Unsubscribes from the given events
NameTypeOptionalDescription
events(keyof TEvents)[]NoNone
Inherited from BaseRedisBroker