Skip to content

Commit 0d343d7

Browse files
committed
chore: various small improvements
* add _self in client * measure tmp client creation * improve logging * set relaxed timeouts on tmp client
1 parent a656392 commit 0d343d7

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

packages/client/lib/client/commands-queue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default class RedisCommandsQueue {
8787
this.#maintenanceCommandTimeout = ms;
8888

8989
let counter = 0;
90+
const total = this.#toWrite.length;
9091

9192
// Overwrite timeouts of all eligible toWrite commands
9293
for(const node of this.#toWrite.nodes()) {
@@ -114,7 +115,7 @@ export default class RedisCommandsQueue {
114115
};
115116
signal.addEventListener('abort', command.timeout.listener, { once: true });
116117
};
117-
dbgMaintenance(`Total of ${counter} timeouts reset to ${ms}`);
118+
dbgMaintenance(`Total of ${counter} of ${total} timeouts reset to ${ms}`);
118119
}
119120

120121
get isPubSubActive() {

packages/client/lib/client/enterprise-maintenance-manager.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,24 @@ export default class EnterpriseMaintenanceManager {
181181
dbgMaintenance("Pausing writing of new commands to old socket");
182182
this.#client._pause();
183183

184+
dbgMaintenance("Creating new tmp client");
185+
let start = performance.now();
184186
const tmpClient = this.#client.duplicate({
185-
maintPushNotifications: "disabled",
186187
socket: {
187188
...this.#options.socket,
188189
host,
189190
port,
190191
},
191192
});
192-
193+
dbgMaintenance(`Tmp client created in ${( performance.now() - start ).toFixed(2)}ms`);
193194
dbgMaintenance(`Connecting tmp client: ${host}:${port}`);
195+
start = performance.now();
196+
tmpClient._maintenanceUpdate({
197+
relaxedCommandTimeout: this.#options.maintRelaxedCommandTimeout,
198+
relaxedSocketTimeout: this.#options.maintRelaxedSocketTimeout,
199+
});
194200
await tmpClient.connect();
195-
dbgMaintenance(`Connected to tmp client`);
201+
dbgMaintenance(`Connected to tmp client in ${(performance.now() - start).toFixed(2)}ms`);
196202
// 3 [EVENT] New socket connected
197203

198204
//TODO

packages/client/lib/client/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ export default class RedisClient<
937937
_ejectSocket(): RedisSocket {
938938
const socket = this._self.#socket;
939939
// @ts-ignore
940-
this.#socket = null;
940+
this._self.#socket = null;
941941
socket.removeAllListeners();
942942
return socket;
943943
}
@@ -957,10 +957,10 @@ export default class RedisClient<
957957
* @internal
958958
*/
959959
_maintenanceUpdate(update: MaintenanceUpdate) {
960-
this.#socket.inMaintenance = update.inMaintenance;
961-
this.#socket.setMaintenanceTimeout(update.relaxedSocketTimeout);
962-
this.#queue.inMaintenance = update.inMaintenance;
963-
this.#queue.setMaintenanceCommandTimeout(update.relaxedCommandTimeout);
960+
this._self.#socket.inMaintenance = update.inMaintenance;
961+
this._self.#socket.setMaintenanceTimeout(update.relaxedSocketTimeout);
962+
this._self.#queue.inMaintenance = update.inMaintenance;
963+
this._self.#queue.setMaintenanceCommandTimeout(update.relaxedCommandTimeout);
964964
}
965965

966966
/**

0 commit comments

Comments
 (0)