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 with 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.
- In the upper-left corner of the page, select the region where the instance is deployed.
- On the Instances page, find the target instance, click the instance ID or click Manage in the Actions column.
- On the Instance Information page, click System Parameters in the left-side navigation pane.
- On the page that appears, find the timeout parameter and click Modify in the Actions column.
- In the dialog box that appears, follow these steps to specify the parameter.
- Change the value of the timeout parameter based on your requirements.
- Click OK.
Call API operations to set parameters
You can also call the ModifyInstanceConfig operation to set parameters.