Registry / database / nestjs-ioredis

nestjs-ioredis

JSON →
library0.1.8jsnpmunverified

A NestJS module wrapping ioredis for Redis integration. Version 0.1.8 is current as of 2023, with limited release cadence (latest release over a year ago). It provides a declarative @RedisModule for root configuration and async factory, plus @InjectRedisClient decorator to inject named Redis clients. Differentiator: integrates deeply with NestJS DI and supports multiple connection instances via name tokens. Note: package name is 'nestjs-ioredis' but GitHub repo is 'nest-redis'. There is no official stable release beyond 0.x and no breaking change policy is documented.

npm install nestjs-ioredis
INSTALL
IMPORT
SIG · NESTJS-IOREDIS
N
nestjs-ioredis
databasejavascriptv0.1.8
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-ioredis'
import RedisModule from 'nestjs-ioredis'
Named export, not default. Always use curly braces.
InjectRedisClient
import { InjectRedisClient } from 'nestjs-ioredis'
import { InjectRedisClient } from 'nestjs-ioredis/dist'
Main entry, no deep import needed.
RedisClient
import { RedisClient } from 'ioredis'
import { RedisClient } from 'nestjs-ioredis'
RedisClient type is from ioredis, not re-exported by this package.

Registers Redis with a single connection using forRoot() with host, port, and optional password from env.

import { Module } from '@nestjs/common'; import { RedisModule } from 'nestjs-ioredis'; @Module({ imports: [ RedisModule.forRoot({ host: process.env.REDIS_HOST ?? 'localhost', port: Number(process.env.REDIS_PORT) ?? 6379, password: process.env.REDIS_PASSWORD ?? '', }), ], }) export class AppModule {}
Debug
Known issues
breakingforRoot() now expects an array of connection configs, not a single object
fix
Wrap single config in array: forRoot([{...}]) or use spread. The README shows both forms, but array is required.
affects: >=0.1.0
deprecatedforAsync() signature changed; 'options' object now optional
fix
Use forAsync({}, { useFactory, inject }) - first argument must be empty object, not omitted.
affects: >=0.1.0
gotchaInjectRedisClient with name '0' defaults to first unnamed connection
fix
Use explicit 'name' property in config, then inject with that name. Name '0' is reserved for the default connection.
affects: >=0.0.1
gotchaTypeScript warns: 'Redis.Redis' is deprecated, use 'Redis' directly
fix
Use `import Redis from 'ioredis'` and type as `Redis` not `Redis.Redis`.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'nestjs-ioredis' or its corresponding type declarations
Missing @types or wrong import path
fix
npm install nestjs-ioredis and ensure tsconfig.json includes node_modules types.
RedisModule.forRoot is not a function
Trying to use default import instead of named import
fix
Use import { RedisModule } from 'nestjs-ioredis';
Connection lost: The server is not connected to a Redis server
Redis server not running or wrong host/port
fix
Check REDIS_HOST and REDIS_PORT env vars, or start Redis locally.
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies
@nestjs/commonoptionalPeer dependency for NestJS decorators and module system
ioredisrequiredUnderlying Redis client library
Agent activity
7 hits · last 30 days
node
6
Resources
nestjs-ioredis — npm install nestjs-ioredis · libregistry