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

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

Open
rishabh-banknovo opened this issue Jan 11, 2023 · 2 comments

Comments

@rishabh-banknovo
Copy link

rishabh-banknovo commented Jan 11, 2023

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**

@simplenotezy
Copy link

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

@br0ck-w00d
Copy link

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

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

No branches or pull requests

3 participants