RPCRedisBroker

export declare class RPCRedisBroker<TEvents extends Record<string, any[]>, TResponses extends Record<keyof TEvents, any>> extends BaseRedisBroker<TEvents, TResponses> implements IRPCBroker<TEvents, TResponses>
export declare class RPCRedisBroker<TEvents extends Record<string, any[]>, TResponses extends Record<keyof TEvents, any>> extends BaseRedisBroker<TEvents, TResponses> 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(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(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(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(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, TResponses>

Implements

IRPCBroker<TEvents, TResponses>
NameConstraintsOptionalDefaultDescription
TEventsRecord<string, any[]>NoNone
TResponsesRecord<keyof TEvents, any>NoNone
constructor(redisClient, options)
Constructs a new instance of the RPCRedisBroker class
NameTypeOptionalDescription
redisClientRedisNoNone
optionsRPCRedisBrokerOptionsNoNone
Protected
listening:boolean
Whether this broker is currently polling events
Inherited from BaseRedisBroker
ProtectedReadonly
Options this broker is using
ProtectedReadonly
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
call(event, data, timeoutDuration?):Promise<TResponses[Event]>
Makes an RPC call
NameTypeOptionalDescription
eventEventNoNone
dataTEvents[Event]NoNone
timeoutDurationnumberYesNone
destroy():Promise<void>
Destroys the broker, closing all connections
Inherited from BaseRedisBroker
Protected
emitEvent(id, event, data):void
NameTypeOptionalDescription
idBufferNoNone
eventstringNoNone
dataunknownNoNone
Protected
listen():Promise<void>
Begins polling for events, firing them to listen
Inherited from BaseRedisBroker
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