【发布时间】:2022-01-23 11:00:57
【问题描述】:
我正在尝试通过关注此official guide 和此tutorial 为我的nestjs-graphql 项目设置Redis caching。我正在遵循提到的确切步骤,但我收到了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();
}
}
【问题讨论】:
-
尝试按照@ArekRGW 的建议添加缓存的导入。
import { Cache } from 'cache-manager';
标签: javascript node.js caching redis nestjs