Skip to content

Commit 60c2af9

Browse files
marcbachmannluin
authored andcommittedMar 14, 2022
fix: Reset loaded script hashes to force a reload of scripts after reconnect of redis
1 parent 1e10c95 commit 60c2af9

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed
 

‎lib/Redis.ts

+10-32
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ class Redis extends Commander {
7272
private _autoPipelines = new Map();
7373
private _runningAutoPipelines = new Set();
7474

75-
// Prepare a cache of scripts and setup a interval which regularly clears it
76-
private _addedScriptHashes: { [sha: string]: true } = {};
77-
private _addedScriptHashesCleanInterval?: ReturnType<
78-
typeof setInterval
79-
> | null = null;
80-
8175
constructor(port: number, host: string, options: RedisOptions);
8276
constructor(path: string, options: RedisOptions);
8377
constructor(port: number, options: RedisOptions);
@@ -187,13 +181,6 @@ class Redis extends Commander {
187181
process.nextTick(this.emit.bind(this, status, arg));
188182
}
189183

190-
private clearAddedScriptHashesCleanInterval() {
191-
if (this._addedScriptHashesCleanInterval) {
192-
clearInterval(this._addedScriptHashesCleanInterval);
193-
this._addedScriptHashesCleanInterval = null;
194-
}
195-
}
196-
197184
/**
198185
* Create a connection to Redis.
199186
* This method will be invoked automatically when creating a new Redis instance
@@ -213,18 +200,6 @@ class Redis extends Commander {
213200
return;
214201
}
215202

216-
// Make sure only one timer is active at a time
217-
this.clearAddedScriptHashesCleanInterval();
218-
219-
// Scripts need to get reset on reconnect as redis
220-
// might have been restarted or some failover happened
221-
this._addedScriptHashes = {};
222-
223-
// Start the script cache cleaning
224-
this._addedScriptHashesCleanInterval = setInterval(() => {
225-
this._addedScriptHashes = {};
226-
}, this.options.maxScriptsCachingTime);
227-
228203
this.connectionEpoch += 1;
229204
this.setStatus("connecting");
230205

@@ -343,8 +318,6 @@ class Redis extends Commander {
343318
* If you want to wait for the pending replies, use Redis#quit instead.
344319
*/
345320
disconnect(reconnect = false) {
346-
this.clearAddedScriptHashesCleanInterval();
347-
348321
if (!reconnect) {
349322
this.manuallyClosing = true;
350323
}
@@ -626,10 +599,6 @@ class Redis extends Commander {
626599
command.setTimeout(this.options.commandTimeout);
627600
}
628601

629-
if (command.name === "quit") {
630-
this.clearAddedScriptHashesCleanInterval();
631-
}
632-
633602
let writable =
634603
this.status === "ready" ||
635604
(!stream &&
@@ -677,7 +646,16 @@ class Redis extends Commander {
677646
command.args
678647
);
679648
}
680-
(stream || this.stream).write(command.toWritable());
649+
650+
if (stream) {
651+
if (stream.isPipeline) {
652+
stream.write(command.toWritable(stream.destination.redis.stream));
653+
} else {
654+
stream.write(command.toWritable(stream));
655+
}
656+
} else {
657+
this.stream.write(command.toWritable(this.stream));
658+
}
681659

682660
this.commandQueue.push({
683661
command: command,

0 commit comments

Comments
 (0)
Please sign in to comment.