Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connection): ignore error when setting custom end status #2473

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading