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.

Did you find a proper solution to this problem. I have encountered the same issue and the answers have not really helped. I am getting around it by type casting like this imports:[CacheModule.register( { store: redisStore as unknown as CacheStore ... but it feels a little too hackie – Linda Scoon Mar 24 at 22:45 nevermind I've discovered that this solution has issues too. But there is an alternative solution at github.com/dabroek/node-cache-manager-redis-store/issues/40, it is to use cache-manager-redis-yet instead of cache-manager-redis-store – Linda Scoon Mar 25 at 1:33

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 {}
                ok but when importing redis it gives me the following error message: The module '"redis"' does not have any member 'ClientOpts' exported
– Luciano Pulido
                Nov 30, 2022 at 21:22
                either ways, that a type and it can work without importing client options and not passing it in CacheModule.register<ClientOpts>
– shoaib30
                Dec 2, 2022 at 6:56

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.