redis2_read_timeout

The `redis2_read_timeout` directive sets the maximum time to read the response from the Redis server in milliseconds.

Syntaxredis2_read_timeout time;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The redis2_read_timeout directive specifies the duration (in milliseconds) that NGINX will wait for a response from the Redis server before timing out the operation. It is particularly important in scenarios where multiple or heavy requests are made to Redis, as setting this timeout ensures that if a response is not received within the specified period, NGINX will gracefully terminate the connection to avoid hanging requests.

Placed within the contexts of http, server, or location, this directive accepts a single argument representing the timeout value. For optimal performance and user experience, configuring this directive according to the expected response time from your Redis instance is crucial. A too short timeout might lead to unnecessary failures, while a too long timeout could result in unresponsive user interactions if the Redis server is slow to respond.

In practice, it is advised to set this timeout in conjunction with other timeout-related directives such as redis2_connect_timeout and redis2_send_timeout for comprehensive timeout handling, forming a complete timeout strategy for interactions with Redis.

Config Example

http {
    server {
        location /example {
            redis2_pass 127.0.0.1:6379;
            redis2_read_timeout 5000;  # 5 seconds
            redis2_query get example_key;
        }
    }
}

Setting this timeout too low may cause legitimate requests to fail if Redis is under heavy load.

If used in conjunction with other timeout directives, ensure their values are consistent to avoid unexpected behaviors.

← Back to all directives