You can set the timeout parameter to specify a timeout period for client connections. Then, ApsaraDB for Redis can close client connections that have timed out to recycle resources.

Prerequisites

An ApsaraDB for Redis instance of the standard edition is created, and the engine version of the instance is Redis 4.0 and later.

Note You cannot modify the timeout parameter for cluster instances or read/write splitting instances of ApsaraDB for Redis.

Manage client connections in ApsaraDB for Redis

In common scenarios, you can use clients to manage connections. For example, clients can allocate connections, monitor the status of connections, and recycle resources in the connection pool. By default, ApsaraDB for Redis does not close a client connection even if a client has been idle for a long period of time. However, we recommend that you specify the timeout parameter in core applications to allow ApsaraDB for Redis to recycle resources. If resources are not recycled in a timely manner after exceptions occur on clients, the connection pool may be full of idle client connections. This may result in a service crash. Such an issue in core applications may cause serious impact on your business.

The timeout parameter is measured in seconds and the valid values is from 0 to 100000. The default value is 0, which specifies that client connections never time out. To improve performance, ApsaraDB for Redis does not immediately close a client connection when the client connection reaches the timeout period. For example, if the timeout parameter is set to 10 seconds, a client connection may be closed after it is idle for 12 seconds and after many client connections have been created on the shard server. To reduce the latency, you can set a larger value for the hz parameter to increase the frequency of the background task that closes idle connections. For more information, see Change the frequency of background tasks.

Specify the parameter in the ApsaraDB for Redis console

  1. Log on to the ApsaraDB for Redis console.
  2. On the top of the page, select the region where the instance is deployed.
  3. On the Instances page, click the Instance ID of the instance.
  4. In the left-side navigation pane, click System Parameters.
  5. On the page that appears, find the timeout parameter and click Modify in the Actions column.
    Change the value of the parameter
  6. In the dialog box that appears, change the value of the timeout parameter.
  7. Click OK.

Related API operations

ModifyInstanceConfig