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.
An ApsaraDB for Redis instance of the standard edition is created, and the engine version of the instance is Redis 4.0 and later.
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
- Log on to the ApsaraDB for Redis console.
- On the top of the page, select the region where the instance is deployed.
- On the Instances page, click the Instance ID of the instance.
- In the left-side navigation pane, click System Parameters.
- On the page that appears, find the timeout parameter and click Modify in the Actions column.
- In the dialog box that appears, change the value of the timeout parameter.
- Click OK.