liaoliaots / nestjs-redis

Redis module for Nest framework (node.js). Support node-redis & ioredis.
MIT License
388 stars 70 forks source link

update nestjs peer dependencies to v10 #518

Closed duysolo closed 1 month ago

duysolo commented 1 year ago

PR Type

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

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?

Other information

duysolo commented 1 year ago

@liaoliaots could you have a look on this?

mahsumurebe commented 1 year ago

Hi @duysolo

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

You can follow PR #517

hotsezus commented 1 year ago

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

hotsezus commented 1 year ago

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

mahsumurebe commented 1 year ago

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

jorcelinojunior commented 1 year ago

Hi @liaoliaots

Can you check the pull request?

bistacos commented 1 year ago

Hey @liaoliaots , can you take a look here?

evyros commented 1 year ago

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

Johannes-Schiel commented 1 year ago

How is the state of this ?

Beni312 commented 8 months ago

any update? I need this upgrade

bistacos commented 7 months ago

@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 commented 7 months ago

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

liaoliaots commented 1 month ago

Please check out the new version: version 10 of @liaoliaots/nestjs-redis.