Redis(ioredis) module for NestJS framework.
- Support redis and cluster
- Support health check
- Specify single or multiple clients
- Inject a redis/cluster client via
@InjectRedis()
and@InjectCluster()
decorator - Get a redis/cluster client via
RedisService
andClusterService
- Easy to test via
getRedisToken()
andgetClusterToken()
For the legacy V2 or V3@next documentation, click here.
Statements | Branches | Functions | Lines |
---|---|---|---|
$ npm install --save @liaoliaots/nestjs-redis ioredis
$ npm install --save-dev @types/ioredis
$ yarn add @liaoliaots/nestjs-redis ioredis
$ yarn add --dev @types/ioredis
$ npm install --save @liaoliaots/nestjs-redis@2 ioredis @nestjs/terminus@7
$ npm install --save-dev @types/ioredis
$ yarn add @liaoliaots/nestjs-redis@2 ioredis @nestjs/terminus@7
$ yarn add --dev @types/ioredis
This package exports getRedisToken()
and getClusterToken()
functions that return an internal injection token based on the provided context. Using this token, you can provide a mock implementation of the redis/cluster client using any of the standard custom provider techniques, including useClass
, useValue
, and useFactory
.
const module: TestingModule = await Test.createTestingModule({
providers: [{ provide: getRedisToken('your namespace'), useValue: mockClient }, YourService]
}).compile();
A working example is available here.
- select db
π€ LiaoLiao
- Github: @liaoliaots
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a βοΈ if this project helped you!