Skip to content

Commit

Permalink
fix(connection): ignore error when setting custom end status (#2473)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Apr 3, 2024
1 parent 66cf7c7 commit 3e17e45
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions src/classes/redis-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,16 @@ export class RedisConnection extends EventEmitter {
};

handleEnd = () => {
reject(lastError || new Error(CONNECTION_CLOSED_ERROR_MSG));
if (client.status !== 'end') {
reject(lastError || new Error(CONNECTION_CLOSED_ERROR_MSG));
} else {
if (lastError) {
reject(lastError);
} else {
// when custon 'end' status is set we already closed
resolve();
}
}
};

increaseMaxListeners(client, 3);
Expand Down Expand Up @@ -215,34 +224,37 @@ export class RedisConnection extends EventEmitter {

this.loadCommands();

this.version = await this.getRedisVersion();
if (this.skipVersionCheck !== true && !this.closing) {
if (
isRedisVersionLowerThan(this.version, RedisConnection.minimumVersion)
) {
throw new Error(
`Redis version needs to be greater or equal than ${RedisConnection.minimumVersion} Current: ${this.version}`,
);
}
if (this._client['status'] !== 'end') {
this.version = await this.getRedisVersion();
if (this.skipVersionCheck !== true && !this.closing) {
if (
isRedisVersionLowerThan(this.version, RedisConnection.minimumVersion)
) {
throw new Error(
`Redis version needs to be greater or equal than ${RedisConnection.minimumVersion} ` +
`Current: ${this.version}`,
);
}

if (
isRedisVersionLowerThan(
this.version,
RedisConnection.recommendedMinimumVersion,
)
) {
console.warn(
`It is highly recommended to use a minimum Redis version of ${RedisConnection.recommendedMinimumVersion}
Current: ${this.version}`,
);
if (
isRedisVersionLowerThan(
this.version,
RedisConnection.recommendedMinimumVersion,
)
) {
console.warn(
`It is highly recommended to use a minimum Redis version of ${RedisConnection.recommendedMinimumVersion}
Current: ${this.version}`,
);
}
}
}

this.capabilities = {
canDoubleTimeout: !isRedisVersionLowerThan(this.version, '6.0.0'),
};
this.capabilities = {
canDoubleTimeout: !isRedisVersionLowerThan(this.version, '6.0.0'),
};

this.status = 'ready';
this.status = 'ready';
}

return this._client;
}
Expand Down

0 comments on commit 3e17e45

Please sign in to comment.