#why the store is not connected in Redis

4 messages · Page 1 of 1 (latest)

crimson vale
#

i want to use redis in my nest js project but still i getting an error at option - store :redisStore

Type 'typeof import("C:/sample/complete-rest-api/node_modules/cache-manager-redis-store/dist/index")' is not assignable to type '(string | CacheStoreFactory | CacheStore)

small sun
#

I would recommend you to use this lib @liaoliaots/nestjs-redis, it's pretty straightforward, and i implemented it yesterday.

The usage is really simple:

// AppModule
import { RedisModule } from '@liaoliaots/nestjs-redis'

@Module({
  imports:[
    RedisModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          readyLog: true,
          closeClient: true,
          config: {
            host: configService.get<string>('redis.KATCHAU_CACHE_HOST'),
            port: configService.get<number>('redis.KATCHAU_CACHE_PORT'),
            password: configService.get<string>('redis.KATCHAU_CACHE_PASSWORD'),
          },
        }
      },
    }),
  ],
})


// Your service
import { InjectRedis } from '@liaoliaots/nestjs-redis'
import Redis from 'ioredis'

@Injectable()
export class MyService {
  constructor(
    @InjectRedis() private readonly cacheManager: Redis,
  ){}

  async doSomething(){
    await this.cacheManager.set(id, {...})
  }
}

#

Take a look into its documentation, you can implement it in many different ways

gilded vault
#
CacheModule.register({
      isGlobal: true,
      store:async ()=>{
       return await redisStore.redisStore({
url:'redis://username:password@host:6379/0'
        }) as any
      }  ,
    }),

I just encountered the same problem and solved it this way. You can refer to it