Closed softzer0 closed 2 months ago
You should use the @nestjs/cache-manager
, follow the caching doc, and replace cache-manager-redis-store
with cache-manager-redis-yet
Module
// redis.module.ts
import { CacheModule } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';
// import * as redisStore from 'cache-manager-redis-store'; replace the redisStore
import { redisStore } from 'cache-manager-redis-yet'; //
import { RedisService } from './redis.service';
@Module({
imports: [
CacheModule.register({
isGlobal: true,
store: redisStore,
url: `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`,
}),
],
providers: [RedisService],
exports: [RedisService],
})
export class RedisModule {}
Service
// redis.service.ts
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Inject } from '@nestjs/common';
import { Cache } from 'cache-manager';
import { RedisStore } from 'cache-manager-redis-yet';
import { RedisClientType } from 'redis';
export class RedisService {
client: RedisClientType;
constructor(
@Inject(CACHE_MANAGER)
private readonly cacheManager: Cache,
) {
this.client = (this.cacheManager.store as RedisStore).client as RedisClientType;
}
async getKeysFromKeySet(keySet: string): Promise<string[]> {
const keys: string[] = await this.client.sMembers(keySet);
return keys;
}
}
Yeah, this turned out to be the bogus issue in the end and it was some other problem which I managed to solve. My apologies, I totally forgot that I made this issue.
Describe the bug I'm using the latest version of
cache-manager-redis-yet
from NPM which is 5.0.0, and I'm using it in a combination with NestJS. However, as the title says, I'm encountering an issue where I can't access the Redis client instance, even though I correctly define the cache manager using this wrapper.This is what I see when I inspect
this.cacheManager.store
object:There's no
client
even though it should be there...How To Reproduce Some simple example code of NestJS service:
Module:
EDIT: This might be a bogus issue, as I'm currently doing other checks and seems like the issue is deeper than I've initially thought.