Skip to content

Commit

Permalink
Merge branch 'master' of github.com:redis/node-redis
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale committed Nov 24, 2022
2 parents 3b36963 + 13ad249 commit 549a779
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,15 @@ export default class RedisClient<
return this.#isolationPool.use(fn);
}

multi(): RedisClientMultiCommandType<M, F, S> {
MULTI(): RedisClientMultiCommandType<M, F, S> {
return new (this as any).Multi(
this.multiExecutor.bind(this),
this.#options?.legacyMode
);
}

multi = this.MULTI;

async multiExecutor(
commands: Array<RedisMultiQueuedCommand>,
selectedDB?: number,
Expand Down
26 changes: 18 additions & 8 deletions packages/client/lib/client/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default class RedisSocket extends EventEmitter {
throw new Error('Socket already opened');
}

this.#isOpen = true;
return this.#connect();
}

Expand All @@ -116,7 +117,6 @@ export default class RedisSocket extends EventEmitter {
}

try {
this.#isOpen = true;
this.#socket = await this.#createSocket();
this.#writableNeedDrain = false;
this.emit('connect');
Expand All @@ -142,7 +142,7 @@ export default class RedisSocket extends EventEmitter {
await promiseTimeout(retryIn);
}
retries++;
} while (!this.#isReady);
} while (this.#isOpen && !this.#isReady);
}

#createSocket(): Promise<net.Socket | tls.TLSSocket> {
Expand Down Expand Up @@ -203,6 +203,8 @@ export default class RedisSocket extends EventEmitter {
this.#isReady = false;
this.emit('error', err);

if (!this.#isOpen) return;

this.#connect(true).catch(() => {
// the error was already emitted, silently ignore it
});
Expand All @@ -219,14 +221,22 @@ export default class RedisSocket extends EventEmitter {
}

disconnect(): void {
if (!this.#socket) {
if (!this.#isOpen) {
throw new ClientClosedError();
} else {
this.#isOpen = this.#isReady = false;
}

this.#socket.destroy();
this.#socket = undefined;
this.#isOpen = false;
this.#disconnect();
}

#disconnect(): void {
this.#isReady = false;

if (this.#socket) {
this.#socket.destroy();
this.#socket = undefined;
}

this.emit('end');
}

Expand All @@ -237,7 +247,7 @@ export default class RedisSocket extends EventEmitter {

this.#isOpen = false;
await fn();
this.disconnect();
this.#disconnect();
}

#isCorked = false;
Expand Down
4 changes: 3 additions & 1 deletion packages/client/lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(commands: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => {
return this.#execute(
Expand All @@ -237,6 +237,8 @@ export default class RedisCluster<
);
}

multi = this.MULTI;

getMasters(): Array<ClusterNode<M, F, S>> {
return this.#slots.getMasters();
}
Expand Down

0 comments on commit 549a779

Please sign in to comment.