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

update nestjs peer dependencies to v10

Open duysolo opened this issue 1 year ago • 12 comments

PR Type

Update peer dependencies of @nestjs to the latest version (v10).

  • [ ] Bugfix
  • [x] Feature
  • [ ] Code style update (formatting, local variables)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Other... Please describe:

What is the current behavior?

NestJS recently released version 10 approximately two weeks ago, resulting in our project encountering the following warning:

─┬ @liaoliaots/nestjs-redis 9.0.5
│ ├── ✕ unmet peer @nestjs/common@^9.0.0: found 10.0.4
│ └── ✕ unmet peer @nestjs/core@^9.0.0: found 10.0.4

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • [ ] Yes
  • [x] No

Other information

duysolo avatar Jun 30 '23 15:06 duysolo

@liaoliaots could you have a look on this?

duysolo avatar Jul 03 '23 05:07 duysolo

Hi @duysolo

I have a PR that I opened eighteen days ago. It has not been checked yet.

You can follow PR #517

mahsumurebe avatar Jul 04 '23 14:07 mahsumurebe

@mahsumurebe it looks like we also need to upgrade node.js required version to 16 based on NestJS Migration Guide

hotsezus avatar Jul 07 '23 11:07 hotsezus

Actually, it looks like !518 is actually more acurate beacause it does update everything needed and introduces major update to package

hotsezus avatar Jul 07 '23 11:07 hotsezus

I’ve already changed the nodejs required version. Please check this

mahsumurebe avatar Jul 07 '23 11:07 mahsumurebe

Hi @liaoliaots

Can you check the pull request?

jorcelinojunior avatar Jul 13 '23 22:07 jorcelinojunior

Hey @liaoliaots , can you take a look here?

bistacos avatar Jul 27 '23 22:07 bistacos

Looking forward to this one, it's blocking us from upgrading to v10

evyros avatar Aug 11 '23 13:08 evyros

How is the state of this ?

Johannes-Schiel avatar Oct 18 '23 13:10 Johannes-Schiel

any update? I need this upgrade

Beni312 avatar Mar 09 '24 11:03 Beni312

@Beni312 The repo owner is not making updates, I've removed nestjs-redis from my dependencies and rolled my own RedisService using ioredis:

import { Injectable, Logger, OnModuleDestroy } from '@nestjs/common';
import { Redis } from 'ioredis';
import { RedisException } from './redis.exception';

@Injectable()
export class RedisService implements OnModuleDestroy {
  private client: Redis | undefined; // undefined bc it might not exist due to lazy connect

  private createClient() {
    this.client = new Redis({
      host: process.env.REDIS_HOST,
      port: Number(process.env.REDIS_PORT),
      password: process.env.REDIS_PASSWORD,
      retryStrategy: (times: number) => {
        if (times > 10) {
          return undefined;
        }
        // retry at longer intervals based on the number of retries so far, max 3 seconds
        return Math.min(times * 100, 3000);
      },
    });

    if (!this.client) {
      throw new RedisException('Could not connect to Redis');
    }

    this.client.on('error', (error) => {
      Logger.error(`Redis error: ${error}`);
    });

    return this.client;
  }

  getClient(): Redis {
    if (!this.client) {
      this.createClient(); // lazy connect
    }
    return this.client;
  }

  async onModuleDestroy() {
    if (this.client) {
      return new Promise((resolve, reject) => {
        this.client?.quit((err, reply) => {
          if (err) {
            return reject(err);
          }
          resolve(reply);
        });
      });
    }
  }
}

...usable like so

import { RedisService } from 'src/redis/redis.service';

export class YourClass {
  constructor(
    private readonly redisService: RedisService,
  ) {
  // ...
  }
}
  
 async yourFunction() {
   const redis = this.redisService.getClient();
   await redis.set(
     // see ioredis documentation for basic usage
   );
 } 

Hope that helps.

bistacos avatar Mar 11 '24 17:03 bistacos

@Beni312 The repo owner is not making updates, I've removed nestjs-redis from my dependencies and rolled my own RedisService using ioredis:

import { Injectable, Logger, OnModuleDestroy } from '@nestjs/common';
import { Redis } from 'ioredis';
import { RedisException } from './redis.exception';

@Injectable()
export class RedisService implements OnModuleDestroy {
  private client: Redis | undefined; // undefined bc it might not exist due to lazy connect

  private createClient() {
    this.client = new Redis({
      host: process.env.REDIS_HOST,
      port: Number(process.env.REDIS_PORT),
      password: process.env.REDIS_PASSWORD,
      retryStrategy: (times: number) => {
        if (times > 10) {
          return undefined;
        }
        // retry at longer intervals based on the number of retries so far, max 3 seconds
        return Math.min(times * 100, 3000);
      },
    });

    if (!this.client) {
      throw new RedisException('Could not connect to Redis');
    }

    this.client.on('error', (error) => {
      Logger.error(`Redis error: ${error}`);
    });

    return this.client;
  }

  getClient(): Redis {
    if (!this.client) {
      this.createClient(); // lazy connect
    }
    return this.client;
  }

  async onModuleDestroy() {
    if (this.client) {
      return new Promise((resolve, reject) => {
        this.client?.quit((err, reply) => {
          if (err) {
            return reject(err);
          }
          resolve(reply);
        });
      });
    }
  }
}

...usable like so

import { RedisService } from 'src/redis/redis.service';

export class YourClass {
  constructor(
    private readonly redisService: RedisService,
  ) {
  // ...
  }
}
  
 async yourFunction() {
   const redis = this.redisService.getClient();
   await redis.set(
     // see ioredis documentation for basic usage
   );
 } 

Hope that helps.

I put it in my application, works well, thanks :)

Beni312 avatar Mar 12 '24 18:03 Beni312