gpt4 book ai didi

javascript - 类型 'get' 上不存在属性 'Cache' 。 NestJs 项目

转载 作者:行者123 更新时间:2023-12-05 00:35:05 26 4
gpt4 key购买 nike

我正在尝试设置 Redis caching对于我的nestjs - graphql按照这个 official guide 进行项目这个tutorial .我正在按照提到的确切步骤进行操作,但我收到了 Property 'get' does not exist on type 'Cache'. 的此错误。
这是确切的代码

import {User} from './user.entity'
import {Resolver, Query, ResolveField, Args, Parent, Mutation} from '@nestjs/graphql'
import { UsersService } from './users.service';
import { PostsService } from '../posts/posts.service';
import { CurrentUser } from 'src/auth/auth.resolver';
import { CACHE_MANAGER, Inject, UseGuards } from '@nestjs/common';
import { GqlAuthGuard } from 'src/auth/graphql-auth.guard';

@Resolver(of => User)
export class UsersResolver {
constructor(
@Inject(CACHE_MANAGER) private cacheManager: Cache,
private usersService: UsersService,
private postsService: PostsService,
) {}

@Query()
async getUsers() {
const value = await this.cacheManager.get('key'); //<--- This is what gives the error
if(value){ // cacheManager doesn't have a get
console.log({ // but both of the mentioned tutorials
data: value, // use the same exact property
loadsFrom: 'redis cache'
})
}
return await this.usersService.findAll();
}
}

最佳答案

导入Cache用于@Inject(CACHE_MANAGER) private cacheManager: Cache来自 cache-manager从“缓存管理器”导入{缓存};

关于javascript - 类型 'get' 上不存在属性 'Cache' 。 NestJs 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70445343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com