redis2_connect_timeout
The `redis2_connect_timeout` directive sets the timeout duration for establishing a connection to a Redis server.
Описание
The redis2_connect_timeout directive in the NGINX upstream module for Redis defines the maximum duration in milliseconds that the server will attempt to connect to a specified Redis instance before timing out. This is essential for applications that need to maintain quick response times and cannot afford to wait indefinitely for a connection to a backend Redis database.
The directive accepts a single argument, which is a time duration specified in milliseconds. For instance, setting the timeout to 1000 would mean that NGINX will wait for up to one second to establish a connection with the Redis server. If the connection cannot be made within this period, the operation will fail and NGINX will return an error to the client. This can help in optimizing resource usage and improving application performance by avoiding delays caused by unresponsive Redis instances.
This directive can be used in various context levels such as http, server, or location, making it versatile for different configurations depending on how the upstream Redis servers are set up. It is particularly useful in environments where multiple Redis servers may be used, and individual timeouts can be configured for each.
Пример конфига
server {
location /example {
redis2_pass 127.0.0.1:6379;
redis2_connect_timeout 1000; # 1 second timeout for connecting to Redis
}
}If the redis2_connect_timeout is set too low, it may lead to frequent connection timeout errors, especially under high load or when the Redis server is slow to respond.
This directive does not apply to already established connections; it only affects the initial connection attempts.
Make sure to configure timeouts that align with your application's performance expectations and backend availability.