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

"total_retry_time" not include connection timeout #1444

Open
qishibo opened this issue Jun 5, 2019 · 1 comment
Open

"total_retry_time" not include connection timeout #1444

qishibo opened this issue Jun 5, 2019 · 1 comment

Comments

@qishibo
Copy link

qishibo commented Jun 5, 2019

  • Version: 2.8.0
  • Platform: node v8.11.2 on ubuntu
  • Description: Connection to an IP which can't be reached, emit a retry event after a very very long time during every retrying... What I meas the total_retry_time not include connecting time, and retry event will be emited after another connection timeout, if the connection timeout not setted, default is quite a long time.
// connect to an IP not exists
redis.createClient(6379, '999.999.999.999', options);

I solved this with a connect_timeout param which is abandoned by official...this will solve the first time connecting timeout problems...(max connection timeout set to 2S before emiting retry event )

image

@ljluestc
Copy link

ljluestc commented Sep 2, 2024


const redis = require('redis');

// Redis connection options
const options = {
  // Set the socket timeout to 2 seconds
  socket_timeout: 2000, // Timeout in milliseconds
};

// Create Redis client with options
const client = redis.createClient({
  port: 6379,
  host: '999.999.999.999',
  ...options
});

// Event handler for connection error
client.on('error', (err) => {
  console.error('Redis connection error:', err);
});

// Event handler for retry
client.on('reconnecting', (details) => {
  console.log('Retrying connection...', details);
});

// Event handler for successful connection
client.on('ready', () => {
  console.log('Redis client connected and ready.');
});

// Event handler for end of connection
client.on('end', () => {
  console.log('Redis client connection closed.');
});

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

2 participants