liaoliaots/nestjs-redis

Redis Connection Hangup when trying to do any set/get methods with Nestjs

rishabh-banknovo opened this issue · 2 comments

Module file:

import { Module, Global } from '@nestjs/common';
import { RedisModule } from '@liaoliaots/nestjs-redis';
import { ConfigService } from '@nestjs/config';
import { RedisConfig } from '../../config/config.interface';
import { ConfigKey } from '../../common/enum';

const modules = [
RedisModule.forRootAsync({
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
const redisConfig = config.get(ConfigKey.LOGIN_REDIS);
console.log(redisConfig);
return {
readyLog: true,
errorLog: true,
config: {

      host: 'xxxxxxxx',
      port: xxx,
      password: 'xxxx',

    },
  };
},

}),
];

@global()
@module({
imports: modules,
exports: modules,
})
export class RedisConnectionModule {}

Service File:

import { Injectable } from '@nestjs/common';
import { RedisService as RedisInternalService, DEFAULT_REDIS_NAMESPACE } from '@liaoliaots/nestjs-redis';
import Redis from 'ioredis';

@Injectable()
export class RedisService {

private readonly cacheManager: Redis;

constructor(private readonly redisService: RedisInternalService) {
this.cacheManager = this.redisService.getClient(DEFAULT_REDIS_NAMESPACE);
}

// Currently creating a custom function but will replace once increment function available with mem cache
async incrementValue(key, expiry: number = 30 * 60): Promise {
const currentValue: string = await this.cacheManager.get(key);
const safeIntValue = currentValue === null ? 0 : parseInt(currentValue, 10);
await this.cacheManager.set(key, safeIntValue + 1, 'EX', expiry);
// await this.cacheManager.set('key', 'value', 'EX', expiry);
return safeIntValue + 1;
}

async setLoginToken(
token: string,
value,
expiry = 30 * 60 * 60 * 24,
): Promise {
return this.cacheManager.set(token, value, 'EX', expiry);
}

async getLoginToken(token: string): Promise {
return this.cacheManager.get(token);
}
}

Dependencies:

"@liaoliaots/nestjs-redis": "^9.0.5",
"ioredis": "^5.2.4",
"@nestjs/apollo": "^10.1.4",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
"@nestjs/graphql": "^10.1.5",

Redis server is AWS cluster and i am pointing to master node.

**Request goes to infinte loading.

Note: With simple redis setup with redis version 3.1.2 , things working fine.

Stuck with these problem from last few days. Need help on priority**

@rishabh-banknovo I'd suggest you properly format and indent your code

@rishabh-banknovo Were you able to solve this issue?