• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

캐시 사용할때

22.03.12 15:19 작성 조회수 244

0

cache를 사용하려는데 Redis 를 store로 사용하려고합니다.

 

그래서 아래와 같이 사용하는것은 알겠는데,

 

import { Module, CacheModule } from '@nestjs/common';
import { CacheService } from './cache.service';
import * as redisStore from 'cache-manager-ioredis';

@Module({
imports: [
CacheModule.register({
store: redisStore,
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
ttl: 0,
}),
],
providers: [CacheService],
exports: [CacheService],
})
export class RedisCacheModule {}

 

import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { Cache } from 'cache-manager';

@Injectable()
export class CacheService {
constructor(
@Inject(CACHE_MANAGER)
private readonly cache: Cache,
) {}

async get({ key }: { key: string }) {
return await this.cache.get(key);
}

async set({
key,
value,
ttl = 0,
}: {
key: string;
value: any;
ttl?: number;
}) {
await this.cache.set(key, value, { ttl });
return true;
}

async delete({ key }: { key: string }) {
await this.cache.del(key);
return true;
}
}

 

get , set ,del 등 기본적인 명령 외에 redis명령어인 scan 등을 사용하고 싶은데 사용방법이 있을까요?

 

로우쿼리로라도 날릴수있다면 날리고싶은데,,, 어떻게 방법이 있는지 알고싶습니다.

답변 1

답변을 작성해보세요.

0

캐시스토어에서 기능을 제공하지 않으면 안 될것 같고 따로 레디스클라이언트 연결해서 쿼리날리셔야할 것 같습니다.