npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@liaoliaots/nestjs-redis-health

v9.0.4

Published

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

Downloads

31,452

Readme

NPM Downloads Stargazers Issues Vulnerabilities License

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

| Statements | Branches | Functions | Lines | | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | Statements | Branches | Functions | Lines |

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

| Name | Type | Default | Required | Description | | --------------- | --------- | ----------- | -------- | ----------------------------------------------------------------------------------------------------- | | type | 'redis' | undefined | true | Server type. You must specify what Redis server type you use. Possible values are "redis", "cluster". | | client | Redis | undefined | true | The client which the health check should get executed. | | timeout | number | 1000 | false | The amount of time the check should require in ms. | | memoryThreshold | number | undefined | false | The maximum amount of memory used by redis in bytes. |

Cluster

| Name | Type | Default | Required | Description | | ------ | ----------- | ----------- | -------- | ----------------------------------------------------------------------------------------------------- | | type | 'cluster' | undefined | true | Server type. You must specify what Redis server type you use. Possible values are "redis", "cluster". | | client | Cluster | undefined | true | The client which the health check should get executed. |

License

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