liaoliaots/nestjs-redis

[Question]Set readyLog True make logger keep logging for every 3 seconds...

AnCoSONG opened this issue · 4 comments

As mentioned in the title, I set readyLog: true and found that it just keep logging default: Connected successfully to server.

Is this a feature ? Or maybe I made a mistake somewhere?

[Nest] 35946  - 2022/05/08 06:00:28     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:31     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:35     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:38     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:41     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:44     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:48     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:51     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:54     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:00:57     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:01:00     LOG [RedisModule] default: Connected successfully to server
[Nest] 35946  - 2022/05/08 06:01:03     LOG [RedisModule] default: Connected successfully to server

I need more information about this unexpected behavior.
Can you show me your module config, packages versions, node version and operating system?

I need more information about this unexpected behavior. Can you show me your module config, packages versions, node version and operating system?

  • RedisModule Config
RedisModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        readyLog: true,
        errorLog: true,
        config: {
          host: configService.get('redis.host'),
          port: +configService.get<number>('redis.port'),
          password: configService.get('redis.password'),
          db: 0, // for cache
        },
      }),
    }),
  • Version: 8.1.1
  • Node version: v 16.10.0
  • operating system: macOS 12.3 on M1 and intel chip (both tested)

Although it logs for every 3 seconds, the service seem to work normally.

The other information that I think would be useful is that I use nginx to reverse proxy the redis which is in the internal network of tencent cloud. Here is the nginx conf of redis.

stream {
        upstream redis {
                hash $remote_addr consistent;
                server 172.21.0.14:6379 max_fails=3 fail_timeout=30s;
        }

        server {
                listen <port>;
                proxy_connect_timeout 1s;
                proxy_timeout 3s;
                proxy_pass redis;
        }
}

so emmm, do you have any clue about this problem?

@AnCoSONG
According to the official nginx documentation, you should increase the value of proxy_timeout(default value is 10m) OR set readyLog to false as your need.

Syntax: proxy_timeout timeout;
Default: proxy_timeout 10m;
Context: stream, server;

It sets the timeout between two successive read or write operations on client or proxied server connections. If no data is transmitted within this time, the connection is closed.

For example, proxy_timeout is 3s and set retryStrategy to () => 2000, then npm run start:dev.
If no read/write operation within 3 seconds, nginx will automatically close the connection, but ioredis will try to reconnect when the connection is lost, so the RedisModule will print a ready message every 5 seconds(3s + 2000ms).

@AnCoSONG According to the official nginx documentation, you should increase the value of proxy_timeout(default value is 10m) OR set readyLog to false as your need.

Syntax: proxy_timeout timeout;
Default: proxy_timeout 10m;
Context: stream, server;

It sets the timeout between two successive read or write operations on client or proxied server connections. If no data is transmitted within this time, the connection is closed.

For example, proxy_timeout is 3s and set retryStrategy to () => 2000, then npm run start:dev. If no read/write operation within 3 seconds, nginx will automatically close the connection, but ioredis will try to reconnect when the connection is lost, so the RedisModule will print a ready message every 5 seconds(3s + 2000ms).

Thank you for your explanation! I tried default proxy_timeout and problem was solved.