Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@liaoliaots/nestjs-redis-health

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liaoliaots/nestjs-redis-health

Redis(ioredis) health checks module for Nest framework (node.js).

  • 9.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NPM Downloads Stargazers Issues Vulnerabilities License

Nest Logo

Nest Redis Health Module

Redis(ioredis) health checks module for Nest framework (node.js).
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Settings
  5. License
  6. Package dependency overview

About The Project

Features

  • Both redis & cluster are supported.
  • Health: Checks health of redis & cluster server.
  • Rigorously tested: With 20+ tests and 100% code coverage.

Test coverage

StatementsBranchesFunctionsLines
StatementsBranchesFunctionsLines

Getting Started

Prerequisites

This lib requires Node.js >=12.22.0, NestJS ^9.0.0, ioredis ^5.0.0.

Installation

# with npm
npm install @nestjs/terminus @liaoliaots/nestjs-redis-health ioredis
# with yarn
yarn add @nestjs/terminus @liaoliaots/nestjs-redis-health ioredis
# with pnpm
pnpm add @nestjs/terminus @liaoliaots/nestjs-redis-health ioredis

Usage

1, import TerminusModule and RedisHealthModule into the imports array:

// app.module.ts
import { Module } from '@nestjs/common';
import { TerminusModule } from '@nestjs/terminus';
import { RedisHealthModule } from '@liaoliaots/nestjs-redis-health';
import { AppController } from './app.controller';

@Module({
  imports: [TerminusModule, RedisHealthModule],
  controllers: [AppController]
})
export class AppModule {}

2, let's setup AppController:

// app.controller.ts
import { Controller, Get } from '@nestjs/common';
import { HealthCheckService, HealthCheck, HealthCheckResult } from '@nestjs/terminus';
import { RedisHealthIndicator } from '@liaoliaots/nestjs-redis-health';
import Redis from 'ioredis';

@Controller()
export class AppController {
  private readonly redis: Redis;

  constructor(private readonly health: HealthCheckService, private readonly redisIndicator: RedisHealthIndicator) {
    this.redis = new Redis({ host: 'localhost', port: 6379, password: 'authpassword' });
  }

  @Get('health')
  @HealthCheck()
  async healthChecks(): Promise<HealthCheckResult> {
    return await this.health.check([
      () => this.redisIndicator.checkHealth('redis', { type: 'redis', client: this.redis, timeout: 500 })
    ]);
  }
}

3, if your redis server is reachable, you should now see the following JSON-result when requesting http://localhost:3000/health with a GET request:

{
  "status": "ok",
  "info": {
    "redis": {
      "status": "up"
    }
  },
  "error": {},
  "details": {
    "redis": {
      "status": "up"
    }
  }
}

INFO: Read more about @nestjs/terminus here.

HINT: Both TerminusModule and RedisHealthModule are not global modules.

Settings

Redis

NameTypeDefaultRequiredDescription
type'redis'undefinedtrueServer type. You must specify what Redis server type you use. Possible values are "redis", "cluster".
clientRedisundefinedtrueThe client which the health check should get executed.
timeoutnumber1000falseThe amount of time the check should require in ms.
memoryThresholdnumberundefinedfalseThe maximum amount of memory used by redis in bytes.

Cluster

NameTypeDefaultRequiredDescription
type'cluster'undefinedtrueServer type. You must specify what Redis server type you use. Possible values are "redis", "cluster".
clientClusterundefinedtrueThe client which the health check should get executed.

License

Distributed under the MIT License. See LICENSE for more information.

Keywords

FAQs

Package last updated on 01 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc