Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
–
–
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
import type { ClientOpts } from 'redis';
import * as redisStore from 'cache-manager-redis-store';
import { CacheModule, Module } from '@nestjs/common';
import { AppController } from './app.controller';
@Module({
imports: [
CacheModule.register<ClientOpts>({
store: redisStore,
// Store-specific configuration:
host: 'localhost',
port: 6379,
controllers: [AppController],
export class AppModule {}
–
–
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 of cache-manager-redis-store
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.