最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

在 Nest js 中,我添加了 Redis 作为缓存管理器。并且在调用set函数后在Redis中找不到任何添加的数据。那么,我错过了什么吗?

网站源码admin33浏览0评论

在 Nest js 中,我添加了 Redis 作为缓存管理器。并且在调用set函数后在Redis中找不到任何添加的数据。那么,我错过了什么吗?

在 Nest js 中,我添加了 Redis 作为缓存管理器。并且在调用set函数后在Redis中找不到任何添加的数据。那么,我错过了什么吗?

节点版本:v14.15.4 Nest-js 版本:9.0.0

应用程序.module.ts 这是代码。 在应用程序模块中,我将 Redis 注册为缓存管理器。

@Module({
  imports: [
    CacheModule.register({
      isGlobal: true,
      store: redisStore,
      url: process.env.REDIS_URL,
    })
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

服务.ts 缓存数据方法用于存储带有键的数据。 -> 问题是设置函数不保存任何东西

并获取Data,用于按键返回数据。

@Injectable()
export class SomeService {
      constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {}

      async cacheData(key: string, data): Promise<void> {
        await this.cacheManager.set(key, data);
      }

      async getData(key: string, data): Promise<any> {
        return this.cacheManager.get(key);
      }
}




它不会在运行时抛出任何错误。

回答如下:

i 遇到了和你一样的问题,解决这个问题的方法是使用安装命令将 cache-manager-redis-store 的版本更改为 2.0.0,如'npm i [email protected]. 0'

完成这一步后,可以找到redisStore的使用,然后就可以链接数据库了。

发布评论

评论列表(0)

  1. 暂无评论