diff --git a/packages/client/lib/client/commands-queue.ts b/packages/client/lib/client/commands-queue.ts index a4029779fc8..842725e427d 100644 --- a/packages/client/lib/client/commands-queue.ts +++ b/packages/client/lib/client/commands-queue.ts @@ -56,6 +56,8 @@ export default class RedisCommandsQueue { return this.#pubSub.isActive; } + #pushHandlers: Map unknown>; + constructor( respVersion: RespVersions, maxLength: number | null | undefined, @@ -65,6 +67,7 @@ export default class RedisCommandsQueue { this.#maxLength = maxLength; this.#onShardedChannelMoved = onShardedChannelMoved; this.decoder = this.#initiateDecoder(); + this.#pushHandlers = new Map unknown>(); } #onReply(reply: ReplyUnion) { @@ -109,13 +112,26 @@ export default class RedisCommandsQueue { onErrorReply: err => this.#onErrorReply(err), onPush: push => { if (!this.#onPush(push)) { - + const handler = this.#pushHandlers.get(push[0].toString()); + if (handler === undefined) { + return; + } + handler(push) } }, getTypeMapping: () => this.#getTypeMapping() }); } + setPushCallback(type: string, callback?: (push: any[]) => unknown) { + if (callback === undefined) { + this.#pushHandlers.delete(type); + return; + } + + this.#pushHandlers.set(type, callback); + } + addCommand( args: CommandArguments, options?: CommandOptions