Estoy tratando de configurar el almacenamiento en Redis caching
para mi proyecto nestjs
- graphql
siguiendo esta guía oficial y este tutorial . Estoy siguiendo los pasos exactos que se mencionan, pero recibo este error de que Property 'get' does not exist on type 'Cache'.
Aquí está el código exacto
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(); } }
Importar el Cache
utilizado en
@Inject(CACHE_MANAGER) private cacheManager: Cache
del cache-manager
import { Cache } from 'cache-manager';
No hay mucho código, pero una cosa que me viene a la mente es que Nest no pudo resolver la dependencia o la resolvió incorrectamente. No veo ninguna importación de tipo Cache
, mire los documentos que ha proporcionado (cita a continuación), tal vez ayude.
La clase Cache se importa del administrador de caché, mientras que el token CACHE_MANAGER del paquete @nestjs/common.