@nestjs-redis/health-indicator
v0.12.1
Published
A comprehensive Redis health indicator for NestJS applications using the Terminus health check library
Maintainers
Readme
@nestjs-redis/health-indicator
Redis health indicator for NestJS with first-class Terminus integration.
Features
- Plug-and-play Terminus health checks
- Works with existing
@nestjs-redis/clientconnections - Supports multiple Redis instances
- Type-safe, production-ready
Installation
Recommended: Install the complete toolkit
npm install @nestjs-redis/kit redisAlternative: Install health-indicator package only
npm install @nestjs-redis/health-indicator redisQuick Start
Note: Examples use
@nestjs-redis/kitimports (recommended). If you installed only this package, import from@nestjs-redis/health-indicatorand@nestjs-redis/clientinstead.
// app.module.ts
import { Module } from '@nestjs/common';
import { TerminusModule } from '@nestjs/terminus';
import { RedisHealthIndicator, RedisModule } from '@nestjs-redis/kit';
@Module({
imports: [
RedisModule.forRoot({
type: 'client',
options: { url: 'redis://localhost:6379' },
}),
TerminusModule,
],
providers: [RedisHealthIndicator],
})
export class AppModule {}// health.controller.ts
import { Controller, Get } from '@nestjs/common';
import { HealthCheck, HealthCheckService } from '@nestjs/terminus';
import { InjectRedis, RedisHealthIndicator } from '@nestjs-redis/kit';
import type { RedisClientType } from 'redis';
@Controller('health')
export class HealthController {
constructor(
private readonly health: HealthCheckService,
private readonly redis: RedisHealthIndicator,
@InjectRedis() private readonly redisClient: RedisClientType,
) {}
@Get()
@HealthCheck()
check() {
return this.health.check([
() => this.redis.isHealthy('redis', { client: this.redisClient }),
]);
}
}Multiple Instances
@Controller('health')
export class HealthController {
constructor(
private readonly health: HealthCheckService,
private readonly redis: RedisHealthIndicator,
@InjectRedis() private readonly mainRedis: RedisClientType,
@InjectRedis('cache') private readonly cacheRedis: RedisClientType,
) {}
@Get()
@HealthCheck()
check() {
return this.health.check([
() => this.redis.isHealthy('redis-main', { client: this.mainRedis }),
() => this.redis.isHealthy('redis-cache', { client: this.cacheRedis }),
]);
}
}Links
- Root repo: CSenshi/nestjs-redis
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Contributing
Please see the root contributing guidelines.
License
MIT © CSenshi
