memcached_next_upstream_tries

The `memcached_next_upstream_tries` directive configures how many memcached servers to attempt before failing a request.

Syntaxmemcached_next_upstream_tries number;
Default1
Contexthttp, server, location
Arguments1

Description

The memcached_next_upstream_tries directive in NGINX specifies the number of memcached servers that will be tried while communicating with a backend cache upon encountering certain defined errors. The directive's main purpose is to enhance fault tolerance during cache access by allowing NGINX to attempt requests against another memcached server, should the current one be unreachable or return an error. This can be particularly useful in environments with multiple memcached servers for load balancing and redundancy.

When a request to a memcached server fails due to a connection issue or a server error, NGINX will retry the request on another memcached server up to the number specified by this directive. If all specified attempts fail, the request will ultimately be returned with an error to the client application. It's crucial to note that the effective operation of this directive depends on having multiple memcached servers defined in your memcached settings, otherwise, the directive will have no impact.

The parameter for this directive is a simple integer value that indicates the number of retry attempts. It can be set to 0 if you want to disable attempts on alternate servers, or to 1 or higher to define the specific number of retries. Too many retries can lead to longer response times, while too few can result in more frequent failures if servers are sensitive to transient outages.

Config Example

location /memcached {
    memcached_pass 127.0.0.1:11211;
    memcached_next_upstream_tries 3;
}

Setting too high a number of retries can lead to longer response times, especially in environments with slow networks or busy servers.

If no other memcached servers are configured, increasing the retries will have no effect since there are no alternative servers to connect to.

← Back to all directives