admin管理员组

文章数量:1401673

I'm using ioredis to connect to Redis in my project. I discovered that some of the clients are not closing for too long time, so I've added connectTimeout and connectionName attributes for each Redis client to identify them. Here is how I connect to Redis:

const redis = new Redis({
  host: process.env.REDIS_HOST,
  port: process.env.REDIS_PORT,
  password: process.env.REDIS_PASSWORD,
  username: process.env.REDIS_USERNAME,
  db: process.env.REDIS_DB,
  connectTimeout: 10000,
  connectionName: connectionName,
});

But still, when I connect via Redis CLI and run CLIENT LIST I can see that some clients have idle time bigger than 10000. So it looks like connectTimeout doesn't work. Any idea why?

Here sample output from CLIENT LIST:

I'm using ioredis to connect to Redis in my project. I discovered that some of the clients are not closing for too long time, so I've added connectTimeout and connectionName attributes for each Redis client to identify them. Here is how I connect to Redis:

const redis = new Redis({
  host: process.env.REDIS_HOST,
  port: process.env.REDIS_PORT,
  password: process.env.REDIS_PASSWORD,
  username: process.env.REDIS_USERNAME,
  db: process.env.REDIS_DB,
  connectTimeout: 10000,
  connectionName: connectionName,
});

But still, when I connect via Redis CLI and run CLIENT LIST I can see that some clients have idle time bigger than 10000. So it looks like connectTimeout doesn't work. Any idea why?

Here sample output from CLIENT LIST:

Share Improve this question asked Mar 24 at 8:14 bobbylejbobbylej 405 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I've had this problem in the past as well. I'm sure there's a setting to fix it but I've always just been lazy and call .quit from my code when I'm done with a connection. This runs the QUIT command on Redis and then Redis shuts down the connection immediately instead of wait for it to be timed out.

本文标签: ioredisRedis connectTimeout is setbut client is still aliveStack Overflow