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>Name | Constraints | Optional | Default | Description |
---|---|---|---|---|
TEvents | Record<string, any> | No | None | |
TResponses | Record<keyof TEvents, any> | No | None |
constructor(options)
Constructs a new instance of the
RPCRedisBroker
className | Type | Optional | Description |
---|---|---|---|
options | RPCRedisBrokerOptions | No | None |
listening
:
boolean
Whether this broker is currently polling events
Inherited from BaseRedisBrokerReadonly
Options this broker is using
Readonly
promises
:
Map<string, InternalPromise>
Readonly
STREAM_DATA_KEY
:
Used for Redis queues, see the 3rd argument taken by xadd
Inherited from BaseRedisBrokerReadonly
streamReadClient
:
Redis
Internal copy of the Redis client being used to read incoming payloads
Inherited from BaseRedisBrokerReadonly
subscribedEvents
:
Set<string>
Events this broker has subscribed to
Inherited from BaseRedisBrokercall(event, data, timeoutDuration?)
:
Promise<TResponses[T]>
Makes an RPC call
Name | Type | Optional | Description |
---|---|---|---|
event | T | No | None |
data | TEvents[T] | No | None |
timeoutDuration | number | Yes | None |
destroy()
:
Promise<void>
Destroys the broker, closing all connections
Inherited from BaseRedisBrokerProtected
emitEvent(id, group, event, data)
:
void
Name | Type | Optional | Description |
---|---|---|---|
id | Buffer | No | None |
group | string | No | None |
event | string | No | None |
data | unknown | No | None |
Protected
listen(group)
:
Promise<void>
Begins polling for events, firing them to listen
Name | Type | Optional | Description |
---|---|---|---|
group | string | No | None |
subscribe(group, events)
:
Promise<void>
Subscribes to the given events, grouping them by the given group name
Name | Type | Optional | Description |
---|---|---|---|
group | string | No | None |
events | (keyof TEvents)[] | No | None |
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
Name | Type | Optional | Description |
---|---|---|---|
group | string | No | None |
events | (keyof TEvents)[] | No | None |