When specific data of a Tair (Redis OSS-compatible) instance expires, Tair (Redis OSS-compatible) gradually deletes the expired data based on the default policy. As a result, the expired data still occupies memory space. You can configure a scheduled O&M task in the CloudOps Orchestration Service (OOS) console to scan all keys during off-peak hours by running the SCAN command and immediately delete expired keys to free up memory space.
Background information
To ensure read and write performance, Tair (Redis OSS-compatible) employs the asynchronous deletion logic. When specific data expires, Tair (Redis OSS-compatible) does not immediately delete the expired data. Instead, Tair (Redis OSS-compatible) gradually deletes expired keys by using a combination of active deletion and passive deletion. For active deletion, Tair (Redis OSS-compatible) periodically scans keys in the background and deletes a portion of expired keys. For passive deletion, Tair (Redis OSS-compatible) deletes expired keys when users access these keys. The expired data still occupies memory space. In extreme cases, when a large amount of data simultaneously expires, it takes an extended period of time to delete the expired data and reclaim the occupied memory space.
You can refer to the procedure in this topic to use the OOS service for free to periodically call the FlushExpireKeys operation on your instance. The instance runs the SCAN command to scan all keys and immediately deletes expired keys.
Running the SCAN command to scan all data can cause an increase in CPU load for the instance. We recommend that you run this command during off-peak hours.
Prerequisites
A Resource Access Management (RAM) role is created for OOS to access Tair (Redis OSS-compatible). For more information, see Grant RAM permissions to OOS.
You can attach the AliyunKvstoreFullAccess system policy to the RAM role. After permissions defined in the policy are granted to the role, the role can manage all resources of Tair (Redis OSS-compatible).
You can also create a custom policy that grants the minimum permissions required to allow OOS to call the DescribeInstances and FlushExpireKeys operations of Tair (Redis OSS-compatible). This policy restricts the RAM role only to the current task.
Procedure
Log on to the OOS console.
In the left-side navigation pane, choose
.On the page that appears, click Create.
Configure a scheduled O&M task.
NoteThis topic introduces only the key steps. For information about other parameters, see What is OOS?
Set Scheduled Task
In this example, Executed Periodically is selected as Scheduled Task Type and the task is set to execute at 04:00 and 16:00 every day.
The End Time for Period Execution parameter is set to 2024-03-31 00:00:00, which specifies that the scheduled O&M task ends at this point in time.
Select Template
Search for ACS-Redis-FlushExpireKeys in the Public Template search box and select the template.
Configure Template Parameters
Select the region where the desired instance resides and select the instance.
From the Permissions drop-down list, select the RAM role that is prepared in the Prerequisites section.
Execution Settings(Optional)
You can use the default values for the parameters on this tab.
Click Create. In the dialog box that appears, click OK.
If the value in the Execution Status column is Valid, the task is automatically executed based on the settings specified on the Set Scheduled Task tab.
What to do next
On the Scheduled O&M page, click the execution ID of the created task to go to the task details page. On this page, you can view or modify task information, immediately trigger execution, and view execution history.
Additionally, because expired data has been deleted and memory has been reclaimed, you can also observe a reduction in memory usage on the instance in the performance monitoring module.
References
You can also configure alert O&M tasks in OOS. For example, you can configure an alert O&M task to call the FlushExpireKeys operation to delete expired keys when the average memory usage reaches 90%. The procedure for configuring an alert O&M task is similar to the procedure in this topic. You can choose to configure an alert O&M task. For more information, see Create an alert O&M task.
For more information about how to delete expired data in Tair and Redis, see Clear expired keys in Tair.