Registry / database / nestjs-redis

nestjs-redis

JSON →
library1.3.3jsnpmunverified

A NestJS module for integrating ioredis, providing Redis connection management for NestJS applications. Current stable version is 1.3.3. It supports single and multiple Redis client configurations, synchronous and asynchronous module registration, and customization of ioredis options. Compared to other NestJS Redis packages, it offers a simple API with RedisService to get client instances and supports features like connection pooling and custom error handling. Release cadence is low; last update was in 2020.

npm install nestjs-redis
INSTALL
IMPORT
SIG · NESTJS-REDIS
N
nestjs-redis
databasejavascriptv1.3.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RedisModule
import { RedisModule } from 'nestjs-redis'
const RedisModule = require('nestjs-redis').RedisModule
ESM is default; CommonJS requires destructuring.
RedisService
import { RedisService } from 'nestjs-redis'
import RedisService from 'nestjs-redis'
Named export, not default.
RedisOptions
import { RedisOptions } from 'nestjs-redis'
TypeScript interface for options; no UMD bundle.

Registers RedisModule with connection options and uses RedisService to get a client and perform a Redis SET command.

// Install: npm install nestjs-redis ioredis // app.module.ts import { Module } from '@nestjs/common'; import { RedisModule } from 'nestjs-redis'; const options = { host: process.env.REDIS_HOST || 'localhost', port: parseInt(process.env.REDIS_PORT || '6379'), password: process.env.REDIS_PASSWORD || '', }; @Module({ imports: [RedisModule.register(options)], }) export class AppModule {} // test.service.ts import { Injectable } from '@nestjs/common'; import { RedisService } from 'nestjs-redis'; @Injectable() export class TestService { constructor(private readonly redisService: RedisService) {} async setKey(key: string, value: string): Promise<void> { const client = await this.redisService.getClient('default'); await client.set(key, value); } }
Debug
Known issues
gotchaThe getClient call is async and returns a Promise, not a direct client.
fix
Use await when calling this.redisService.getClient() or handle the promise with .then().
affects: >=1.0.0
deprecatedThe forRootAsync method is deprecated; use registerAsync instead.
fix
Replace forRootAsync with registerAsync.
affects: >=1.1.0
gotchaIf using multiple clients, the name option must be unique; otherwise clients may be overwritten.
fix
Ensure each client config has a distinct 'name' property.
affects: >=1.0.0
gotchaOptions passed to register are ioredis options; ensure all properties are valid for ioredis.
fix
Refer to ioredis documentation for supported options.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'nestjs-redis'
Package not installed or missing dependency
fix
Run 'npm install nestjs-redis' in your project root.
RedisService is not a constructor
Import error - used default import instead of named import
fix
Use 'import { RedisService } from 'nestjs-redis'' instead of 'import RedisService from 'nestjs-redis''.
TypeError: client.set is not a function
Forgot to await getClient or getClient returned undefined
fix
Ensure call: 'const client = await this.redisService.getClient();' and that client name exists.
Upgrade
Version history
1.3.3latest on npm
Audit
Dependencies
@nestjs/commonrequiredPeer dependency for NestJS module decorators and DI
ioredisrequiredUnderlying Redis client library
Agent activity
2 hits · last 30 days
node
2
Resources
nestjs-redis — npm install nestjs-redis · libregistry