nestjs-redis icon indicating copy to clipboard operation
nestjs-redis copied to clipboard

Nest8 + redis still not working with npm

Open lioralon326 opened this issue 2 years ago • 3 comments

Hello,

While working with nestjs-redis package I am getting the following error:

Nest can't resolve dependencies of the RedisCoreModule (Symbol(REDIS_MODULE_OPTIONS), ?). Please make sure that the argument ModuleRef at index [1] is available in the RedisCoreModule context

The issue was supposedly resolved in this issue https://github.com/skunight/nestjs-redis/issues/82, but the changes were never rolled out when working with npm.

Using: "@nestjs/common": "^8.1.1", "@nestjs/core": "^8.1.1",

only workaround in the moment is either moving the package into the project, or using a different nestjs-redis source, like so: "nestjs-redis": "git+https://github.com/skunight/nestjs-redis.git",

I am sure I am not the only one with this issue

lioralon326 avatar Oct 25 '21 09:10 lioralon326

I faced a lot of problems with NestJS 8 and this Redis package, eventually I moved to the cache manager within NestJS as short term fix from the documentation. It works pretty similarly for my use cases.

import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { Cache } from 'cache-manager';

@Injectable()
export class CacheService {
  constructor(@Inject(CACHE_MANAGER) private readonly cache: Cache) {}

  async get(key: string): Promise<string> {
    return this.cache.get(key);
  }

  async set(key: string, value: string, ttl?: number): Promise<string> {
    if (ttl) {
      return this.cache.set(key, value, { ttl });
    }

    return this.cache.set(key, value);
  }
}

oflynned avatar Oct 25 '21 09:10 oflynned

@skunight could you please release npm package with nestj8 fix?

volodyad avatar Jan 25 '22 11:01 volodyad

@skunight looks like propsal of fix is working fine git+https://github.com/skunight/nestjs-redis.git#939f33a7f9b252e872c6edb76a3a860ed053bacf

Could you prepare and publish fix for that, please?

Svaigas avatar Feb 09 '22 08:02 Svaigas