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

@nestjs-kit/redis

v2.0.0

Published

Client-agnostic Redis and Valkey connections for NestJS with isolated named registrations

Readme

@nestjs-kit/redis

Redis and Valkey clients for NestJS, with any client library. Register how a client connects and disconnects; inject the native client by alias.

npm version npm monthly downloads CI

Install

Install the module with one of the client libraries below. Requires Node.js 24+ and NestJS 12 (@nestjs/common and @nestjs/core). Ships ESM, CommonJS, and TypeScript declarations. No client library is bundled or selected by default.

connect creates the client; bootstrap waits for it. disconnect closes it during application shutdown, after every onModuleDestroy and beforeApplicationShutdown hook. Call app.enableShutdownHooks() to also shut down on SIGTERM and other termination signals. Nest runs no lifecycle hooks in modules loaded lazily after app.init(), so close their clients yourself.

ioredis

pnpm add @nestjs-kit/redis ioredis
import { RedisModule } from "@nestjs-kit/redis";
import { Redis } from "ioredis";

RedisModule.register({
  connect: () => new Redis(process.env.REDIS_URL ?? "redis://localhost:6379"),
  disconnect: (client) => client.quit(),
});

ioredis connects in the background, so an unreachable server does not fail bootstrap. To fail it, connect explicitly:

connect: async () => {
  const client = new Redis(url, { lazyConnect: true });
  await client.connect().catch((error: unknown) => {
    client.disconnect();
    throw error;
  });
  return client;
},

iovalkey

pnpm add @nestjs-kit/redis iovalkey
import { RedisModule } from "@nestjs-kit/redis";
import { Valkey } from "iovalkey";

RedisModule.register({
  connect: () => new Valkey(process.env.VALKEY_URL ?? "redis://localhost:6379"),
  disconnect: (client) => client.quit(),
});

iovalkey also connects in the background. To fail bootstrap on an unreachable server, use the ioredis lazyConnect snippet with new Valkey(url, { lazyConnect: true }).

redis (node-redis)

pnpm add @nestjs-kit/redis redis
import { RedisModule } from "@nestjs-kit/redis";
import { createClient } from "redis";

RedisModule.register({
  connect: () =>
    createClient({ url: process.env.REDIS_URL })
      .on("error", (error: Error) => console.error(error))
      .connect(),
  disconnect: (client) => client.close(),
});

node-redis emits socket errors as error events, which end the process without a listener. With a listener, connect() retries an unreachable server, and bootstrap waits until socket.reconnectStrategy returns an Error.

@valkey/valkey-glide

pnpm add @nestjs-kit/redis @valkey/valkey-glide
import { RedisModule } from "@nestjs-kit/redis";
import { GlideClient } from "@valkey/valkey-glide";

RedisModule.register({
  connect: () =>
    GlideClient.createClient({
      addresses: [{ host: "localhost", port: 6379 }],
    }),
  disconnect: (client) => client.close(),
});

createClient resolves once connected. An unreachable server fails bootstrap after advancedConfiguration.connectionTimeout, 2000 ms by default.

Named and async registrations

alias and global are module extras. Each alias gets its own client and shutdown, and an alias may be registered only once per application. global: true makes the client injectable in modules that do not import the registration.

RedisModule.registerAsync<Redis>({
  alias: "cache",
  global: true,
  inject: [ConfigService],
  useFactory: (config: ConfigService) => ({
    connect: () => new Redis(config.getOrThrow("CACHE_REDIS_URL")),
    disconnect: (client) => client.quit(),
  }),
});

constructor(@Inject(getRedisToken("cache")) private readonly cache: Redis) {}

An alias belongs to one registration. To share a client without global, create the registration once and import that DynamicModule object in every module that injects it.

Tokens

getRedisToken() is REDIS_CLIENT; getRedisToken("cache") is REDIS_CLIENT_cache.

getRedisOptionsToken() returns the module-local configuration token for custom providers inside a registration. The options provider is not exported to parent or importing modules; use this helper only for providers added inside that registration or for registration-local tests. The generated builder token is private and is not exported from the package entry point.

Errors

  • A rejected connect fails bootstrap with its error. A connect that returns no client object fails with a TypeError naming the alias.
  • Two modules that register one alias fail bootstrap before any client connects, with an Error naming the alias.
  • Nest runs no shutdown hooks when bootstrap fails, so clients that other registrations already connected stay open. With the default abortOnError: true the process exits; with abortOnError: false or in tests, end the process or close those clients yourself.
  • Nest logs a rejected disconnect and continues shutting down other registrations; app.close() resolves, and the next close() calls disconnect again.
  • A client that replaces the registration's provider, such as a test double from overrideProvider(getRedisToken()), is not passed to disconnect.