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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rineex/ioredis

v1.2.0

Published

Redis adapter for Rineex core modules

Readme

Overview

@rineex/ioredis provides a NestJS integration for ioredis, including:

  • Creating and exporting Redis clients (single instance or cluster) via a configurable module (RedisModule)
  • Injecting clients by name via @InjectRedis()
  • Basic lifecycle management:
    • On application bootstrap: ping all tracked clients and log results
    • On application shutdown: quit() all tracked clients
  • A Terminus health indicator and module (RedisHealthIndicator, RedisHealthModule)

Use this when:

  • You want an ioredis client managed by NestJS DI, with support for multiple named connections.
  • You want the module to close Redis connections on shutdown.

Do not use this when:

  • You do not use NestJS DI (you can use ioredis directly).
  • You need a different Redis library than ioredis.

Public API

Exports

The package exports:

  • RedisModule
  • InjectRedis
  • RedisHealthIndicator, RedisHealthModule
  • RedisModuleOptions, RedisModuleExtraOptions
  • getRedisConnectionToken, getRedisOptionsToken

RedisModule

A NestJS configurable module for provisioning an ioredis client and exporting it under a DI token.

  • register(options: RedisModuleOptions, extras?: RedisModuleExtraOptions)

    • options:
      • type: 'single' | 'cluster'
      • If type: 'single':
        • url?: string
        • options?: import('ioredis').RedisOptions
      • If type: 'cluster':
        • nodes: import('ioredis').ClusterNode[]
        • options?: import('ioredis').ClusterOptions
    • extras:
      • connection?: string (default: 'default')
    • returns: a dynamic Nest module that exports a provider for the client.
  • registerAsync(...)

    • Async variant; the factory must resolve to RedisModuleOptions.
    • Supports the same extras.connection naming behavior.

Injection helpers

  • InjectRedis(connection?: string)

    • Parameter decorator that injects the ioredis client for the given connection name.
    • If connection is omitted, injects the default connection ('default').
  • getRedisConnectionToken(connection?: string): string

    • Returns the DI token used to register/inject the client.
  • getRedisOptionsToken(connection?: string): string

    • Returns the DI token used internally for module options for a given connection.

Health check integration

  • RedisHealthModule

    • Nest module exporting RedisHealthIndicator.
    • Provides a REDIS_HEALTH_INDICATOR client via a factory that calls new Redis() with default settings.
  • RedisHealthIndicator

    • isHealthy(key: string): Promise<import('@nestjs/terminus').HealthIndicatorResult>
    • Behavior:
      • PING succeeds → returns healthy status for key
      • PING fails → throws HealthCheckError with a status payload including message

Usage Examples

Single Redis (default connection)

import { Module, Injectable } from '@nestjs/common';
import type Redis from 'ioredis';
import { InjectRedis, RedisModule } from '@rineex/ioredis';

@Module({
  imports: [
    RedisModule.register({
      type: 'single',
      url: process.env.REDIS_URL ?? 'redis://localhost:6379',
    }),
  ],
})
export class AppModule {}

@Injectable()
export class CacheService {
  constructor(@InjectRedis() private readonly redis: Redis) {}

  async setValue(key: string, value: string) {
    await this.redis.set(key, value);
  }
}

Named connection

@Module({
  imports: [
    RedisModule.register(
      { type: 'single', url: 'redis://localhost:6380' },
      { connection: 'cache' },
    ),
  ],
})
export class AppModule {}
@Injectable()
export class CacheService {
  constructor(@InjectRedis('cache') private readonly redis: Redis) {}
}

Cluster

import type { Cluster } from 'ioredis';
import { Module, Injectable } from '@nestjs/common';
import { InjectRedis, RedisModule } from '@rineex/ioredis';

@Module({
  imports: [
    RedisModule.register(
      {
        type: 'cluster',
        nodes: [{ host: '127.0.0.1', port: 7000 }],
      },
      { connection: 'cluster' },
    ),
  ],
})
export class AppModule {}

@Injectable()
export class ClusterService {
  constructor(@InjectRedis('cluster') private readonly cluster: Cluster) {}
}

Terminus health check

import { Controller, Get } from '@nestjs/common';
import { HealthCheck, HealthCheckService } from '@nestjs/terminus';
import { RedisHealthIndicator } from '@rineex/ioredis';

@Controller('health')
export class HealthController {
  constructor(
    private readonly health: HealthCheckService,
    private readonly redis: RedisHealthIndicator,
  ) {}

  @Get()
  @HealthCheck()
  check() {
    return this.health.check([() => this.redis.isHealthy('redis')]);
  }
}

Behavior & Guarantees

  • Connection naming: if extras.connection is omitted, the connection name is 'default'.
  • Lifecycle:
    • Clients created by RedisModule are tracked via WeakRef and pinged during onApplicationBootstrap().
    • On shutdown, the module attempts to quit() each tracked client; failures are logged and do not throw.
  • Concurrency: clients are shared singletons per DI token; concurrent use follows ioredis semantics.

Operational Notes

  • Configuration
    • For single instances, prefer a url (e.g. redis://host:6379) and pass options for advanced settings.
    • For cluster, supply nodes and optional ClusterOptions.
  • Logging
    • Bootstrap health checks log ping success/failure per client.
    • Shutdown logs success or error when closing connections.
  • Health module default client
    • RedisHealthModule creates a fresh new Redis() with default configuration; override the REDIS_HEALTH_INDICATOR provider if you need to health-check a configured/named connection instead of the default.

Development

pnpm build
pnpm test
pnpm lint
pnpm check-types

License

Apache-2.0