You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-17 19:41:06 +03:00
use the same Multi with duplicated clients
This commit is contained in:
@@ -83,19 +83,22 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
|||||||
}
|
}
|
||||||
|
|
||||||
static create<M extends RedisModules, S extends RedisLuaScripts>(options?: RedisClientOptions<M, S>): RedisClientType<M, S> {
|
static create<M extends RedisModules, S extends RedisLuaScripts>(options?: RedisClientOptions<M, S>): RedisClientType<M, S> {
|
||||||
return new (<any>extendWithModulesAndScripts({
|
const Client = (<any>extendWithModulesAndScripts({
|
||||||
BaseClass: RedisClient,
|
BaseClass: RedisClient,
|
||||||
modules: options?.modules,
|
modules: options?.modules,
|
||||||
modulesCommandsExecutor: RedisClient.commandsExecutor,
|
modulesCommandsExecutor: RedisClient.commandsExecutor,
|
||||||
scripts: options?.scripts,
|
scripts: options?.scripts,
|
||||||
scriptsExecutor: RedisClient.#scriptsExecutor
|
scriptsExecutor: RedisClient.#scriptsExecutor
|
||||||
}))(options);
|
}));
|
||||||
|
|
||||||
|
Client.prototype.Multi = RedisMultiCommand.extend(options);
|
||||||
|
|
||||||
|
return new Client(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly #options?: RedisClientOptions<M, S>;
|
readonly #options?: RedisClientOptions<M, S>;
|
||||||
readonly #socket: RedisSocket;
|
readonly #socket: RedisSocket;
|
||||||
readonly #queue: RedisCommandsQueue;
|
readonly #queue: RedisCommandsQueue;
|
||||||
readonly #Multi: new (...args: ConstructorParameters<typeof RedisMultiCommand>) => RedisMultiCommandType<M, S>;
|
|
||||||
readonly #v4: Record<string, any> = {};
|
readonly #v4: Record<string, any> = {};
|
||||||
#selectedDB = 0;
|
#selectedDB = 0;
|
||||||
|
|
||||||
@@ -120,7 +123,6 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
|||||||
this.#options = options;
|
this.#options = options;
|
||||||
this.#socket = this.#initiateSocket();
|
this.#socket = this.#initiateSocket();
|
||||||
this.#queue = this.#initiateQueue();
|
this.#queue = this.#initiateQueue();
|
||||||
this.#Multi = RedisMultiCommand.extend(options);
|
|
||||||
this.#legacyMode();
|
this.#legacyMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,10 +310,6 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
|||||||
return await promise;
|
return await promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
async #duplicateConnection(fn: (duplicateClient: RedisClientType<M, S>) => Promise<unknown>) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeScript(script: RedisLuaScript, args: Array<string>, options?: ClientCommandOptions): Promise<ReturnType<typeof script['transformReply']>> {
|
async executeScript(script: RedisLuaScript, args: Array<string>, options?: ClientCommandOptions): Promise<ReturnType<typeof script['transformReply']>> {
|
||||||
try {
|
try {
|
||||||
return await this.#sendCommand([
|
return await this.#sendCommand([
|
||||||
@@ -349,7 +347,8 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
|||||||
}
|
}
|
||||||
|
|
||||||
multi(): RedisMultiCommandType<M, S> {
|
multi(): RedisMultiCommandType<M, S> {
|
||||||
return new this.#Multi(
|
// Multi is attached in `create`
|
||||||
|
return new (this as any).Multi(
|
||||||
this.#multiExecutor.bind(this),
|
this.#multiExecutor.bind(this),
|
||||||
this.#options
|
this.#options
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user