Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update nestjs peer dependencies to v10 #518

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

duysolo
Copy link

@duysolo duysolo commented Jun 30, 2023

PR Type

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

  • Bugfix
  • 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
  • No

Other information

@duysolo duysolo requested a review from liaoliaots as a code owner June 30, 2023 15:10
@duysolo
Copy link
Author

duysolo commented Jul 3, 2023

@liaoliaots could you have a look on this?

@mahsumurebe
Copy link

Hi @duysolo

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

You can follow PR #517

@hotsezus
Copy link

hotsezus commented Jul 7, 2023

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

@hotsezus
Copy link

hotsezus commented Jul 7, 2023

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

@mahsumurebe
Copy link

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

@jorcelinojunior
Copy link

Hi @liaoliaots

Can you check the pull request?

@bistacos
Copy link

Hey @liaoliaots , can you take a look here?

@evyros
Copy link

evyros commented Aug 11, 2023

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

@Johannes-Schiel
Copy link

How is the state of this ?

@Beni312
Copy link

Beni312 commented Mar 9, 2024

any update? I need this upgrade

@bistacos
Copy link

@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.

@Beni312
Copy link

Beni312 commented Mar 12, 2024

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants