Redis(ioredis) module for NestJS framework.
- Both redis & cluster are supported: You can also specify multiple clients.
- Health: Checks health of redis & cluster server.
- Rigorously tested: With 120+ tests and 100% code coverage.
- Decorators: Injects redis/cluster client via
@InjectRedis()
and@InjectCluster()
. - Services: Gets redis/cluster client via
RedisService
andClusterService
.
Statements | Branches | Functions | Lines |
---|---|---|---|
- Install
- Redis
- Cluster
- Health Checks
- Examples
- Distributed locks
- Test a class
- Package dependency overview
- TODO
- V2 and V3@next, click here
- V3@latest, click here
- V4, click here
- V5, click here
This package supports both nestjs 7.x and 8.x.
$ npm install --save @liaoliaots/nestjs-redis ioredis
$ npm install --save-dev @types/ioredis
$ yarn add @liaoliaots/nestjs-redis ioredis
$ 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.
-
- COMMAND: SELECT
👤 LiaoLiao
- Github: @liaoliaots
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
This project is MIT licensed.