When data in Tair (Redis OSS-compatible) expires, the instance gradually deletes it based on the default policy. As a result, expired data continues to occupy memory. You can configure a Scheduled O&M task in CloudOps Orchestration Service (OOS) to scan (SCAN) all keys and immediately delete expired keys during off-peak hours. This process releases the occupied memory.
Background information
Tair (Redis OSS-compatible) instances use asynchronous deletion to ensure read and write performance. When data expires, the instance does not delete it immediately. Instead, it gradually deletes expired keys using two methods: active deletion and passive deletion. Active deletion involves a background process that periodically scans for and deletes some expired keys. Passive deletion occurs when a user tries to access an expired key. Because of this process, expired data continues to occupy memory. In extreme cases, when a large amount of data expires at once, the deletion and memory reclamation process can be time-consuming.
This solution uses the free OOS service to periodically call the FlushExpireKeys API. The instance then scans (SCAN) all keys and immediately deletes the expired keys.
The SCAN command scans all data, which increases the CPU load on the instance. Run this task during off-peak hours.
Prerequisites
Create a RAM role for OOS to access the Tair (Redis OSS-compatible) service. For more information, see Set up and grant permissions to a RAM role for OOS.
Grant the AliyunKvstoreFullAccess system policy to the role. This policy allows the RAM role to manage all Tair (Redis OSS-compatible) resources.
Alternatively, you can create a custom policy with the least privilege required. The policy must allow OOS to call the `DescribeInstances` and `FlushExpireKeys` APIs for Tair (Redis OSS-compatible). This limits the role to performing only this task.
Procedure
Go to the OOS console.
In the navigation pane on the left, click .
Click Create.
Configure the scheduled O&M task.
NoteThis topic describes only the key steps. For more information about other parameters, see CloudOps Orchestration Service.
Schedule Settings
For this example, select Executed Periodically. Schedule the task to run at 04:00 and 16:00 every day.

Set End Time to 2026-01-01 00:00:00. The scheduled O&M task stops running at the specified time.
Select a template
In the Public Templates section, search for and select the ACS-Redis-FlushExpireKeys template.
Configure template parameters
Select the region where the instance is located, and then select the target instance.
For Permission Source For Execution, select the RAM role that you created in the Prerequisites section.
Execution settings (Optional)
Keep the default settings on this tab.
Click Create, and then click OK in the dialog box that appears.
When the Execution Status of the task is Active, the task automatically runs based on the Schedule Settings.
What to do next
In the Scheduled O&M task list, click the target Execution ID to go to the task details page. On this page, you can view or modify the task configuration, immediately trigger an execution, or view the execution history.
After the expired data is deleted and the memory is released, you can view the decrease in the instance's Memory Usage in Performance Monitoring.
References
You can also configure Alert and Event O&M in OOS. For example, you can call the FlushExpireKeys API to delete expired keys when the average memory usage reaches 90%. The configuration process is similar to the one described in this topic. To begin, go to . For more information, see Create an alert-triggered O&M task.
For information about how Tair and Redis purge expired keys, see How do Tair and Redis purge expired keys?.