joneqian / nestjs-redis

Redis(ioredis) module for NestJS framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Welcome to @liaoliaots/nestjs-redis πŸ‘‹

npm (tag) npm (scoped with tag) npm GitHub code style: prettier Conventional Commits CodeFactor workflow Maintenance Snyk Vulnerabilities for npm package

Redis(ioredis) module for NestJS framework.

Features πŸš€

  • 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 and ClusterService
  • Easy to test via getRedisToken() and getClusterToken()

Documentation

For the legacy V2 or V3@next documentation, click here.

Test coverage

Statements Branches Functions Lines
Statements Branches Functions Lines

Install

NestJS 8:

$ npm install --save @liaoliaots/nestjs-redis ioredis
$ npm install --save-dev @types/ioredis
$ yarn add @liaoliaots/nestjs-redis ioredis
$ yarn add --dev @types/ioredis

NestJS 7:

$ 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

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('your namespace'), useValue: mockClient }, YourService]
}).compile();

A working example is available here.

TODO

  • select db

Package dependency overview

Author

πŸ‘€ LiaoLiao

🀝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

πŸ“ License

Copyright Β© 2021 LiaoLiao.
This project is MIT licensed.

About

Redis(ioredis) module for NestJS framework

License:MIT License


Languages

Language:TypeScript 98.1%Language:JavaScript 1.7%Language:Shell 0.1%