@nestjs-redis/health-indicator
Version:
A comprehensive Redis health indicator for NestJS applications using the Terminus health check library
148 lines (116 loc) • 4.13 kB
Markdown
<div align="center">
<img src="https://raw.githubusercontent.com/CSenshi/nestjs-redis/main/docs/images/logo.png" alt="NestJS Redis Toolkit Logo" width="120" height="120">
# -redis/health-indicator
**Redis health indicator for NestJS applications with comprehensive monitoring support**
[](https://www.npmjs.com/package/@nestjs-redis/health-indicator)
[](https://www.npmjs.com/package/@nestjs-redis/health-indicator)
[](https://opensource.org/licenses/MIT)
[](https://www.typescriptlang.org/)
[](https://nestjs.com/)
[](https://redis.io/)
_Built on [node-redis](https://github.com/redis/node-redis) • Production-ready • Type-safe • Terminus integration_
</div>
---
## 📋 Table of Contents
- [📦 Installation](#-installation)
- [🚀 Quick Start](#-quick-start)
- [🔧 Configuration](#-configuration)
- [🤝 Contributing](#-contributing)
- [📄 License](#-license)
---
## 📦 Installation
```bash
# Install the package and dependencies
npm install -redis/health-indicator redis
# Or with yarn
yarn add -redis/health-indicator redis
# Or with pnpm
pnpm add -redis/health-indicator redis
```
### Requirements
| Dependency | Version | Required |
| ------------------ | -------------------------------- | ---------- |
| `/common` | ^9.0.0 \|\| ^10.0.0 \|\| ^11.0.0 | ✅ Peer |
| `/terminus` | ^9.0.0 \|\| ^10.0.0 \|\| ^11.0.0 | ✅ Peer |
| `redis` | ^5.0.0 | ✅ Peer |
| `Node.js` | 18+ | ✅ Runtime |
## 🚀 Quick Start
```typescript
// app.module.ts
import { Module } from '@nestjs/common';
import { TerminusModule } from '@nestjs/terminus';
import { RedisModule } from '@nestjs-redis/client';
import { RedisHealthIndicator } from '@nestjs-redis/health-indicator';
import { HealthController } from './health.controller';
export class AppModule {}
```
```typescript
// health.controller.ts
import { Controller, Get } from '@nestjs/common';
import { HealthCheck, HealthCheckService } from '@nestjs/terminus';
import { InjectRedis, type Redis } from '@nestjs-redis/client';
import { RedisHealthIndicator } from '@nestjs-redis/health-indicator';
export class HealthController {
constructor(
private health: HealthCheckService,
private redis: RedisHealthIndicator,
private redisClient: Redis,
) {}
check() {
return this.health.check([
() =>
this.redis.isHealthy('redis', {
client: this.redisClient,
}),
]);
}
}
```
## 🔧 Configuration
### Multiple Redis Instances
```typescript
export class HealthController {
constructor(
private health: HealthCheckService,
private redis: RedisHealthIndicator,
private mainRedis: Redis,
private cacheRedis: Redis,
) {}
check() {
return this.health.check([
() =>
this.redis.isHealthy('redis-main', {
client: this.mainRedis,
}),
() =>
this.redis.isHealthy('redis-cache', {
client: this.cacheRedis,
}),
]);
}
}
```
## 🤝 Contributing
Contributions are welcome! Please see the [main repository](https://github.com/CSenshi/nestjs-redis) for contributing guidelines.
---
## 📄 License
MIT © [CSenshi](https://github.com/CSenshi)