I am trying to implement redis using the packages : "CacheModule" and "cache-manager-redis-store". The latter brings me a type error when assigning it to the store property of the register method of CacheModule.
code where the error occurs:
`
import { Module, CacheModule } from "@nestjs/common";
import { AuthModule } from "./auth/auth.module";
import { MongooseModule } from "@nestjs/mongoose";
import { EnvConfiguration } from "./config/env.config";
import { ConfigModule } from "@nestjs/config";
import { redisStore } from "cache-manager-redis-store";
@Module({
imports: [
ConfigModule.forRoot({
load: [EnvConfiguration],
}),
MongooseModule.forRoot(process.env.MONGODB),
AuthModule,
CacheModule.register({
store: redisStore, <--- HERE THE ERROR HAPPENS
host: "localhost",
port: 6379,
}),
],
controllers: [],
providers: [],
})
export class AppModule {}
`
ERROR:
`
(property) store: (string | CacheStoreFactory | CacheStore) & ((config: RedisClientOptions<RedisModules, RedisFunctions, RedisScripts> & Config) => Promise<...>)
Cache manager. The default value is 'memory' (memory storage). See Different Stores for more information.
Type '(config: RedisClientOptions<RedisModules, RedisFunctions, RedisScripts> & Config) => Promise<RedisStore>' cannot be assigned to type '(string | CacheStoreFactory | CacheStore) & ((config: RedisClientOptions<RedisModules, RedisFunctions, RedisScripts > & Configuration) => Promise<...>)'.
Type '(config: RedisClientOptions<RedisModules, RedisFunctions, RedisScripts> & Config) => Promise<RedisStore>' cannot be assigned to type 'string & ((config: RedisClientOptions<RedisModules, RedisFunctions, RedisScripts> & Config) => Promise<...>)'.
Type '(config: RedisClientOptions<RedisModules, RedisFunctions, RedisScripts> & Config) => Promise<RedisStore>' cannot be assigned to type 'string'.ts(2322)
`
I want to be able to implement redis with nestjs, solving the described problem or with another way of implementing it that works correctly.
3
Answers
Change this:
to this:
or this:
or this:
The method of importing
redisStore
is the problem. The location pointed out as the issue is where the error is being generated.From Nest JS Docs
I think you should check out this github link
https://github.com/dabroek/node-cache-manager-redis-store/issues/40
To sum up for you, they will use
cache-manager-redis-yet
instead ofcache-manager-redis-store