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 { try {
const pong = String( const client = this.getClient(redisUrl);
await this.withTimeout(this.getClient(redisUrl).ping()),
); if (client.status === 'wait' || client.status === 'end') {
await this.withTimeout(client.connect());
}
const pong = String(await this.withTimeout(client.ping()));
return pong === 'PONG' return pong === 'PONG'
? { status: 'ok' } ? { status: 'ok' }
@@ -62,7 +66,7 @@ export class RedisClient implements OnModuleDestroy {
this.client = new Redis(redisUrl, { this.client = new Redis(redisUrl, {
connectTimeout: redisPingTimeoutMs, connectTimeout: redisPingTimeoutMs,
enableOfflineQueue: false, enableOfflineQueue: false,
lazyConnect: false, lazyConnect: true,
maxRetriesPerRequest: 1, maxRetriesPerRequest: 1,
}); });
this.client.on('error', () => undefined); this.client.on('error', () => undefined);