fix: 修复 Redis 健康检查连接时序

This commit is contained in:
湛兮
2026-06-12 06:41:33 +08:00
parent 9292d4f12c
commit 4ca7eb7b1b
+8 -4
View File
@@ -29,9 +29,13 @@ export class RedisClient implements OnModuleDestroy {
}
try {
const pong = String(
await this.withTimeout(this.getClient(redisUrl).ping()),
);
const client = this.getClient(redisUrl);
if (client.status === 'wait' || client.status === 'end') {
await this.withTimeout(client.connect());
}
const pong = String(await this.withTimeout(client.ping()));
return pong === 'PONG'
? { status: 'ok' }
@@ -62,7 +66,7 @@ export class RedisClient implements OnModuleDestroy {
this.client = new Redis(redisUrl, {
connectTimeout: redisPingTimeoutMs,
enableOfflineQueue: false,
lazyConnect: false,
lazyConnect: true,
maxRetriesPerRequest: 1,
});
this.client.on('error', () => undefined);