#can not use store setting in usefactory
1 messages ยท Page 1 of 1 (latest)
How did you import redisStore ? If it is from "cache-manager-redis-store", you have to import it like this :
import * as redisStore from 'cache-manager-redis-store';
Yes did that exactly
Srry for the late response
But i'm trying to have the cache config work in async while also setting the store to redis
But it seems i can only use store: or registerAsync
I need my cake and eat it to situation
My configuration works like this :
CacheModule.registerAsync({ imports: [ConfigModule], useFactory: (config: ConfigService) => ({ store: redisStore, host: config.get('REDIS_HOST'), port: config.get('REDIS_PORT'), auth_pass: config.get('REDIS_PASSWORD'), }), inject: [ConfigService] }),
Maybe your config is not exact ?
still get this
(property) CacheModuleAsyncOptions<{ store: typeof import("/home/weshuiz13/Documents/app/nest-server/node_modules/cache-manager-redis-store/dist/index"); host: string; port: number; }>.useFactory?: (...args: any[]) => CacheModuleOptions<{
store: typeof redisStore;
host: string;
port: number;
}> | Promise<CacheModuleOptions<{
store: typeof redisStore;
host: string;
port: number;
}>>
It's the full error ?
yes
Can you show the whole module ?
that is going to be the app module tho
seems the error was pointing out store: typeof redisStore;
idk why it wanted typeof but the error is gone at least
but the problem is not fully gone tho
Nest can't resolve dependencies of the TwoFactorService (AccountService, PrismaService, ?). Please make sure that the argument CACHE_MANAGER at index [2] is available in the TwoFactorControllerModule context.
Potential solutions:
- If CACHE_MANAGER is a provider, is it part of the current TwoFactorControllerModule?
- If CACHE_MANAGER is exported from a separate @Module, is that module imported within TwoFactorControllerModule?
@Module({
imports: [ /* the Module containing CACHE_MANAGER */ ]
})
It's just the typescript typing, you don't want to put "typeof redisStore" in your config
that leaves this
"cache-manager-redis-store does not support redis v4. In order for the ClientOpts interface to exist and work correctly you need to install the latest redis 3.x.x major release. See this issue to track the progress of this upgrade."
You saw this ?
i know i'm using 3
ok
- If CACHE_MANAGER is a provider, is it part of the current TwoFactorControllerModule?
- If CACHE_MANAGER is exported from a separate @Module, is that module imported within TwoFactorControllerModule?
but CACHE_MANAGER is neither a service or a module
If you defined the CacheModule config isGlobal: true it should work in others modules ..
that's weird
didn't put the global back, but now i did still the same thing...
CacheModule.registerAsync({
imports: [ConfigModule],
// @ts-ignore
useFactory: (config: ConfigService) => ({
isGlobal: true,
store: redisStore,
host: config.redis.host,
port: config.redis.port,
}),
inject: [ConfigService],
}),
the only module that comes before the CacheModule is the configModule
ConfigModule.forRoot({
isGlobal: true,
cache: true,
expandVariables: true,
envFilePath: `./config/env/.${process.env.NODE_ENV}.env`,
//load: [config],
}),
You should use : configService.get('ENV_VAR_HERE') no ?
i did the config a little different tho so i doubt that
i followed https://docs.nestjs.com/techniques/configuration#custom-getter-functions instead
You don't have any stacktrace for the errors ?
This is not very explicit ๐
If TwoFactorService is part of a provider module that is import in your AppModule + you defined the isGlobal: true in the CacheModule configuration... it should work ๐
yes it is part of the app module
i would be making a min repo if i could, but this thing got so big i just cant anymore
Ok.. sorry
no i'm sorry here ๐
isGlobal IIRC is on the same property level as useFactory
yes
please see the message previous message
#1062372813786337320 message
i start to hate this cache
setup a new project to see what went wrong
figured it out
but now i want to do
CacheModule.registerAsync({
imports: [ConfigModule],
inject: [apiConfigService],// custom service
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
useFactory: async (config: apiConfigService) => ({
host: config.redis.host,
port: config.redis.port,
ttl: config.redis.ttl,
store: redisStore,
isGlobal: true,
}),
}),
but what do i do wrong here?
Is your injection token apiConfigService?
i figured out i had to write a custom module
module -> export -> inject -> useFactory
was not aware of this, still appreciate trying to help once again
cant /close it anymore?