Nestjs 中使用nestjs-redis 提示can't resolve dependencies of the RedisCoreModule

发布于 1周前 作者 phonegap100 最后一次编辑是 5天前 来自 分享

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

a.png

使用下面模块:

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 以后的版本没有遇到以上错误请忽略


回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!