1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Merge branch 'master' of github.com:redis/node-redis

This commit is contained in:
Leibale Eidelman
2022-11-24 14:06:20 -05:00
3 changed files with 24 additions and 10 deletions

View File

@@ -619,13 +619,15 @@ export default class RedisClient<
return this.#isolationPool.use(fn); return this.#isolationPool.use(fn);
} }
multi(): RedisClientMultiCommandType<M, F, S> { MULTI(): RedisClientMultiCommandType<M, F, S> {
return new (this as any).Multi( return new (this as any).Multi(
this.multiExecutor.bind(this), this.multiExecutor.bind(this),
this.#options?.legacyMode this.#options?.legacyMode
); );
} }
multi = this.MULTI;
async multiExecutor( async multiExecutor(
commands: Array<RedisMultiQueuedCommand>, commands: Array<RedisMultiQueuedCommand>,
selectedDB?: number, selectedDB?: number,

View File

@@ -105,6 +105,7 @@ export default class RedisSocket extends EventEmitter {
throw new Error('Socket already opened'); throw new Error('Socket already opened');
} }
this.#isOpen = true;
return this.#connect(); return this.#connect();
} }
@@ -116,7 +117,6 @@ export default class RedisSocket extends EventEmitter {
} }
try { try {
this.#isOpen = true;
this.#socket = await this.#createSocket(); this.#socket = await this.#createSocket();
this.#writableNeedDrain = false; this.#writableNeedDrain = false;
this.emit('connect'); this.emit('connect');
@@ -142,7 +142,7 @@ export default class RedisSocket extends EventEmitter {
await promiseTimeout(retryIn); await promiseTimeout(retryIn);
} }
retries++; retries++;
} while (!this.#isReady); } while (this.#isOpen && !this.#isReady);
} }
#createSocket(): Promise<net.Socket | tls.TLSSocket> { #createSocket(): Promise<net.Socket | tls.TLSSocket> {
@@ -203,6 +203,8 @@ export default class RedisSocket extends EventEmitter {
this.#isReady = false; this.#isReady = false;
this.emit('error', err); this.emit('error', err);
if (!this.#isOpen) return;
this.#connect(true).catch(() => { this.#connect(true).catch(() => {
// the error was already emitted, silently ignore it // the error was already emitted, silently ignore it
}); });
@@ -219,14 +221,22 @@ export default class RedisSocket extends EventEmitter {
} }
disconnect(): void { disconnect(): void {
if (!this.#socket) { if (!this.#isOpen) {
throw new ClientClosedError(); throw new ClientClosedError();
} else {
this.#isOpen = this.#isReady = false;
} }
this.#socket.destroy(); this.#isOpen = false;
this.#socket = undefined; this.#disconnect();
}
#disconnect(): void {
this.#isReady = false;
if (this.#socket) {
this.#socket.destroy();
this.#socket = undefined;
}
this.emit('end'); this.emit('end');
} }
@@ -237,7 +247,7 @@ export default class RedisSocket extends EventEmitter {
this.#isOpen = false; this.#isOpen = false;
await fn(); await fn();
this.disconnect(); this.#disconnect();
} }
#isCorked = false; #isCorked = false;

View File

@@ -224,7 +224,7 @@ export default class RedisCluster<
} }
} }
multi(routing?: RedisCommandArgument): RedisClusterMultiCommandType<M, F, S> { MULTI(routing?: RedisCommandArgument): RedisClusterMultiCommandType<M, F, S> {
return new this.#Multi( return new this.#Multi(
(commands: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => { (commands: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => {
return this.#execute( return this.#execute(
@@ -237,6 +237,8 @@ export default class RedisCluster<
); );
} }
multi = this.MULTI;
getMasters(): Array<ClusterNode<M, F, S>> { getMasters(): Array<ClusterNode<M, F, S>> {
return this.#slots.getMasters(); return this.#slots.getMasters();
} }