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

RPCRedisBroker

export declare class RPCRedisBroker<TEvents extends Record<string, any>, TResponses extends Record<keyof TEvents, any>> extends BaseRedisBroker<TEvents> implements IRPCBroker<TEvents, TResponses>
export declare class RPCRedisBroker<TEvents extends Record<string, any>, TResponses extends Record<keyof TEvents, any>> extends BaseRedisBroker<TEvents> implements IRPCBroker<TEvents, TResponses>
RPC broker powered by Redis
Example
// caller.js
import { RPCRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new RPCRedisBroker({ redisClient: new Redis() });

console.log(await broker.call('testcall', 'Hello World!'));
await broker.destroy();

// responder.js
import { RPCRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new RPCRedisBroker({ redisClient: new Redis() });
broker.on('testcall', ({ data, ack, reply }) => {
console.log('responder', data);
void ack();
void reply(`Echo: ${data}`);
});

await broker.subscribe('responders', ['testcall']);
// caller.js
import { RPCRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new RPCRedisBroker({ redisClient: new Redis() });

console.log(await broker.call('testcall', 'Hello World!'));
await broker.destroy();

// responder.js
import { RPCRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new RPCRedisBroker({ redisClient: new Redis() });
broker.on('testcall', ({ data, ack, reply }) => {
console.log('responder', data);
void ack();
void reply(`Echo: ${data}`);
});

await broker.subscribe('responders', ['testcall']);

Extends

BaseRedisBroker<TEvents>

Implements

IRPCBroker<TEvents, TResponses>
NameConstraintsOptionalDefaultDescription
TEventsRecord<string, any>NoNone
TResponsesRecord<keyof TEvents, any>NoNone
constructor(options)
Constructs a new instance of the RPCRedisBroker class
NameTypeOptionalDescription
optionsRPCRedisBrokerOptionsNoNone
Protected
listening:boolean
Whether this broker is currently polling events
Inherited from BaseRedisBroker
ProtectedReadonly
options:Required<RPCRedisBrokerOptions>
Options this broker is using
ProtectedReadonly
promises:Map<string, InternalPromise>
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
call(event, data, timeoutDuration?):Promise<TResponses[T]>
Makes an RPC call
NameTypeOptionalDescription
eventTNoNone
dataTEvents[T]NoNone
timeoutDurationnumberYesNone
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
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