Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/client/lib/client/commands-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export default class RedisCommandsQueue {
return this.#pubSub.isActive;
}

#pushHandlers: Map<string, (push: any[]) => unknown>;

constructor(
respVersion: RespVersions,
maxLength: number | null | undefined,
Expand All @@ -65,6 +67,7 @@ export default class RedisCommandsQueue {
this.#maxLength = maxLength;
this.#onShardedChannelMoved = onShardedChannelMoved;
this.decoder = this.#initiateDecoder();
this.#pushHandlers = new Map<string, () => unknown>();
}

#onReply(reply: ReplyUnion) {
Expand Down Expand Up @@ -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<T>(
args: CommandArguments,
options?: CommandOptions
Expand Down