Registry / database / nestjs-simple-redis-client

nestjs-simple-redis-client

JSON →
library0.0.3jsnpmunverified

A NestJS module providing easy integration with Redis via the `redis` (node-redis) package. Current version 0.0.3 requires NestJS 11, Node.js 24, and npm 11. It supports synchronous and asynchronous module configuration, multiple named connections, injection via `@InjectRedis` decorator or custom token, and automatic cleanup on application shutdown. Key differentiator: bundles the `redis` driver, offers a typed `RedisClientType` injection, and enforces ESM-only usage. Active development.

npm install nestjs-simple-redis-client
INSTALL
IMPORT
SIG · NESTJS-SIMPLE-REDI
N
nestjs-simple-redis-client
databasejavascriptv0.0.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-client'
const { RedisModule } = require('nestjs-redis-client')
ESM-only; requires node >= 24 and npm >= 11
InjectRedis
import { InjectRedis } from 'nestjs-redis-client'
import { InjectRedis } from 'redis'
Custom decorator; not from the redis package
REDIS_CLIENT
import { REDIS_CLIENT } from 'nestjs-redis-client'
export class MyClass { private redis = REDIS_CLIENT }
Constant for default client token; use with @Inject(REDIS_CLIENT) or getRedisToken('default')
getRedisToken
import { getRedisToken } from 'nestjs-redis-client'
import { getRedisToken } from '@nestjs/common'
Utility to get token for a named connection

Basic setup with RedisModule registration and injection of Redis client in a service.

import { Module } from '@nestjs/common'; import { RedisModule } from 'nestjs-redis-client'; import { Injectable } from '@nestjs/common'; import type { RedisClientType } from 'redis'; import { InjectRedis } from 'nestjs-redis-client'; @Module({ imports: [ RedisModule.register({ url: process.env.REDIS_URL ?? 'redis://localhost:6379', isGlobal: true, }), ], }) export class AppModule {} @Injectable() export class MyService { constructor(@InjectRedis() private readonly redis: RedisClientType) {} async set(key: string, value: string) { await this.redis.set(key, value); } async get(key: string) { return this.redis.get(key); } }
Debug
Known issues
gotchaThis package is ESM-only and requires Node.js >= 24 and npm >= 11. CommonJS require() will fail with ERR_REQUIRE_ESM.
fix
Set type: 'module' in package.json and use import/export syntax. Ensure Node.js version >= 24.
affects: >=0.0.0
breakingIf you forget to import RedisModule.registerAsync or misconfigure the factory, the client may never connect silently.
fix
Ensure async factory returns an object with url property. Use ConfigModule and ConfigService for environment variables.
affects: >=0.0.0
gotchaNamed connections must have unique names; using 'default' as a name will conflict with the unnamed default client.
fix
Use distinct names like 'cache' and 'sessions'. The default token REDIS_CLIENT is reserved for the default connection.
affects: >=0.0.0
deprecatedVersion 0.0.3 is the latest but still early; API may change without major version bump.
fix
Pin version to 0.0.3 and monitor for updates. Consider using semver tilde range ~0.0.3 in package.json.
affects: 0.0.0 - 0.0.3
Errors
Common errors & fixes
Cannot find module 'redis' or its corresponding type declarations.
The redis package is bundled but not explicitly installed as a dependency in the consuming project.
fix
Install redis explicitly: npm install redis. Then add import type { RedisClientType } from 'redis'.
RedisClient is not a constructor
Trying to use CJS require with this ESM-only package.
fix
Switch to ESM: set type: 'module' in package.json and use import statements instead of require.
Unsupported Redis URL format
Provided URL missing protocol or invalid format.
fix
Use a standard URL like redis://username:password@host:port/dbindex. Example: redis://:pass@localhost:6379/0.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
@nestjs/commonrequiredPeer dependency for module decorators and DI
@nestjs/corerequiredPeer dependency for NestJS runtime
@nestjs/platform-expressrequiredPeer dependency for shutdown hooks
redisrequiredBundled driver for Redis connectivity
Agent activity
2 hits · last 30 days
node
2
Resources
nestjs-simple-redis-client — npm install nestjs-simple-redis-client · libregistry