fix: 修复 Redis 健康检查连接时序
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user