-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
this.cacheManager.store.client
is undefined
#685
Labels
Comments
softzer0
changed the title
Can't resolve dependency even though the module is being globally imported
May 12, 2024
this.cacheManager.store.client
is undefined
softzer0
changed the title
Can't resolve dependency even though the module is being globally imported
May 12, 2024
this.cacheManager.store.client
is undefined
You should use the
// 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 {}
// 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: