Redis(ioredis) module for NestJS framework.
🚀
Features - Both redis & cluster are supported: You can also specify multiple clients.
- Health: Checks health of redis & cluster server.
- Rigorously tested: With 130+ tests and 100% code coverage.
- Decorators: Injects redis/cluster client via
@InjectRedis()
and@InjectCluster()
. - Services: Retrieves redis/cluster client via
RedisService
andClusterService
.
🧐
Test coverage Statements | Branches | Functions | Lines |
---|---|---|---|
Documentation
Deprecated
- v5, click here
- v6, click here
- v7, click here
Install
This lib requires Node.js >=12.22.0, ioredis ^5.0.0, NestJS 7.x or 8.x.
# with npm
npm install --save @liaoliaots/nestjs-redis ioredis
# with yarn
yarn add @liaoliaots/nestjs-redis ioredis
Test a class
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('namespace'), useValue: mockedClient }, YourService]
}).compile();
A working example is available here.
Future
-
- Microservice strategy
Package dependency overview
Author
- Github: @liaoliaots
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a
📝 License
This project is MIT licensed.