You are reading the documentation for the next version of discord.js. Documentation for v13/v14+ has been moved to old.discordjs.dev

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({ redisClient: 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({ redisClient: 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({ redisClient: 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({ redisClient: 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:Required<RedisBrokerOptions>
Options this broker is using
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
idBuffer_2NoNone
groupstringNoNone
eventstringNoNone
dataunknownNoNone
Protected
listen(group):Promise<void>
Begins polling for events, firing them to listen
NameTypeOptionalDescription
groupstringNoNone
Inherited from BaseRedisBroker
publish(event, data):Promise<void>
Publishes an event
NameTypeOptionalDescription
eventTNoNone
dataTEvents[T]NoNone
subscribe(group, events):Promise<void>
Subscribes to the given events, grouping them by the given group name
NameTypeOptionalDescription
groupstringNoNone
events(keyof TEvents)[]NoNone
Inherited from BaseRedisBroker
unsubscribe(group, events):Promise<void>
Unsubscribes from the given events - it's required to pass the same group name as when subscribing for proper cleanup
NameTypeOptionalDescription
groupstringNoNone
events(keyof TEvents)[]NoNone
Inherited from BaseRedisBroker