cache-manager
cache-manager copied to clipboard
`this.cacheManager.store.client` is undefined
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:
calculatedSize:
ƒ calculatedSize() {\n return lruCache.calculatedSize;\n }
del:
ƒ async del(key) {\n lruCache.delete(key);\n }
dump:
() => lruCache.dump()
get:
async (key) => lruCache.get(key)
keys:
async () => [...lruCache.keys()]
load:
ƒ load(...arguments_) {\n lruCache.load(...arguments_);\n }
There's no client even though it should be there...
How To Reproduce Some simple example code of NestJS service:
import { CACHE_MANAGER } from "@nestjs/cache-manager";
import { RedisCache } from "cache-manager-redis-yet";
export class RedisService {
constructor(
@Inject(CACHE_MANAGER)
private readonly cacheManager: RedisCache
) {}
private async getKeysFromKeySet(keySet: string): Promise<string[]> {
const keys: string[] = await this.cacheManager.store.client.sMembers(keySet);
return keys;
}
}
Module:
import { CacheModule, Module } from '@nestjs/common';
import { RedisClientOptions } from 'redis';
import { redisStore } from 'cache-manager-redis-yet';
import { RedisService } from './redis.service';
@Module({
imports: [
CacheModule.register<RedisClientOptions>({
isGlobal: true,
store: redisStore,
url: `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`,
}),
],
providers: [RedisService],
exports: [RedisService],
})
export class RedisModule {}
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.