import { HealthCheckError, HealthIndicator, HealthIndicatorResult, } from '@nestjs/terminus'; import { Injectable, Logger } from '@nestjs/common'; import { EnvironmentService } from '../environment/environment.service'; import { Redis } from 'ioredis'; @Injectable() export class RedisHealthIndicator extends HealthIndicator { private readonly logger = new Logger(RedisHealthIndicator.name); constructor(private environmentService: EnvironmentService) { super(); } async pingCheck(key: string): Promise { try { const redis = new Redis(this.environmentService.getRedisUrl(), { maxRetriesPerRequest: 15, }); await redis.ping(); return this.getStatus(key, true); } catch (e) { this.logger.error(e); throw new HealthCheckError( `${key} is not available`, this.getStatus(key, false), ); } } }