nestjs-redis 报 Please make sure that the argument ModuleRef at index [1] is available in the RedisCo

nestjs-redis 报错的解决方案

环境

nest8 nestjs-redis

nestjs-redis 报 Please make sure that the argument ModuleRef at index [1] is available in the RedisCoreModule context.

貌似是nestjs-redis 一直没人维护,对nest8以上支持有问题,具体可以看GitHub的issues,一定自己去看

“nestjs-redis”: “^1.3.3”,

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.

Potential solutions:
- If ModuleRef is a provider, is it part of the current RedisCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within RedisCoreModule?
  @Module({
    imports: [ /* the Module containing ModuleRef */ ]
  })

解决方案

nestjs-redis 改为 @chenjm/nestjs-redis 这是本人克隆之后自己用的,看了issues自己判断,某些人大可不必上来就喷,这里只是说明如何解决的,如果有好的,希望不吝赐教。

yarn add @chenjm/nestjs-redis

app.module.ts 模块中引入

app.module.ts

import {
    RedisModule
} from "@chenjm/nestjs-redis";

@Module({
    imports: [
        RedisModule.forRoot({
            closeClient: true,
            readyLog: true,
            config: {
                namespace: 'default',
                host: '127.0.0.1',
                port: 6380,
                password: 'redispassword'
            }
        }),
        CatsModule
    ]
})
export class AppModule {}

也可以配合 @nestjs/config 通过configService 提供配置

import { ConfigModule, ConfigService } from "@nestjs/config";
import { RedisModule } from "@chenjm/nestjs-redis";

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      cache: true,
      envFilePath: `${process.env.NODE_ENV}.env`,
      load: [configuration],
    }),
    RedisModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          closeClient: true,
          readyLog: true,
          config: configService.get("redis"),
        };
      },
    }),
  ],
})
export class AppModule {}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值