Nestjs 中使用nestjs-redis 提示can't resolve dependencies of the RedisCoreModule
Nestjs8中使用nestjs-redis 提示 Nest can’t resolve dependencies of the RedisCoreModule (Symbol(REDIS_MODULE_OPTIONS), ?). Please make sure that the argument ModuleRef at index [1] is available in the RedisCoreModule context
使用下面模块:
https://www.npmjs.com/package/@liaoliaots/nestjs-redis
一、安装
cnpm install @liaoliaots/nestjs-redis ioredis --save
二、修改public.module.ts
import { RedisModule } from 'nestjs-redis';
改为:
import { RedisModule } from '@liaoliaots/nestjs-redis';
RedisModule.register(Config.redisOptions),
改为:
RedisModule.forRoot({
config: Config.redisOptions
}),
三、修改cache.service.ts
import { RedisService } from 'nestjs-redis';
改为:
import { RedisService } from '@liaoliaots/nestjs-redis';
import Redis from 'ioredis';
this.client = await this.redisService.getClient('');
改为
this.client = await this.redisService.getOrNil('default');
如果Nestjs8 或者 Nestjs8.x 以后的版本没有遇到以上错误请忽略