Tair (Redis OSS-compatible) does not delete expired keys immediately. Instead, it relies on active deletion and passive deletion, which means expired keys can linger in memory long after their TTL elapses. If your instance memory is consistently high due to accumulated expired keys, schedule a CloudOps Orchestration Service (OOS) task to call the FlushExpireKeys API during off-peak hours to reclaim that memory proactively. OOS is a free service.
This approach targets expired keys specifically. If high memory usage is caused by large keys (big keys) or hot-key traffic, use a different remediation strategy.
How expiration works
Tair (Redis OSS-compatible) uses two expiration mechanisms:
-
Active deletion: A background process periodically scans for and deletes some expired keys.
-
Passive deletion: A key is deleted only when a client accesses it and the instance detects it has expired.
Because active deletion periodically scans only some keys rather than scanning exhaustively, and passive deletion requires a client access to trigger deletion, expired keys can accumulate and hold memory — especially when a large number of keys expire around the same time.
Calling FlushExpireKeys instructs the instance to run a full SCAN of all keys and immediately delete any that have expired.
The SCAN command scans all keys and increases CPU load on the instance. Schedule this task during off-peak hours. Before scheduling, check your instance's CPU utilization in Performance Monitoring to identify a safe maintenance window.
Prerequisites
Before you begin, ensure that you have:
-
A RAM role that grants OOS permission to access Tair (Redis OSS-compatible). For setup instructions, see Set up and grant permissions to a RAM role for OOS
The RAM role must have one of the following policies attached:
| Option | Policy | Access granted |
|---|---|---|
| System policy (broader access) | AliyunKvstoreFullAccess | Full management access to all Tair (Redis OSS-compatible) resources |
| Custom policy (least privilege) | Custom — see example below | Only kvstore:DescribeInstances and kvstore:FlushExpireKeys |
Example custom policy:
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kvstore:DescribeInstances",
"kvstore:FlushExpireKeys"
],
"Resource": "*"
}
]
}
Create a scheduled O&M task
-
Go to the OOS console.
-
In the navigation pane, click Automated Task > Scheduled O&M.
-
Click Create.
-
Configure the task:
NoteThe following steps cover the key configuration options. For all other parameters, see CloudOps Orchestration Service.
Schedule settings
Select Executed Periodically and set the schedule. In this example, the task runs at 04:00 and 16:00 every day.

Set End Time to
2026-01-01 00:00:00. The task stops running automatically at that time.Select a template
In the Public Templates section, search for and select ACS-Redis-FlushExpireKeys.
Configure template parameters
-
Select the region where the instance is located, then select the target instance.
-
For Permission Source For Execution, select the RAM role you created in the Prerequisites section.
Execution settings (optional)
Keep the default settings.
-
-
Click Create, then click OK in the dialog box.
When the task's Execution Status changes to Active, it runs automatically on the configured schedule.
What's next
-
Monitor the task: In the Scheduled O&M list, click the Execution ID to open the task details page. From there, view or update the task configuration, trigger an immediate execution, or review execution history.
-
Verify memory is reclaimed: After the task runs, check the Memory Usage metric in Performance Monitoring to confirm that memory usage has decreased.
-
Set up alert-based deletion: Instead of a fixed schedule, configure Alert and Event O&M in OOS to call FlushExpireKeys automatically when average memory usage reaches 90%. Go to Automated Task > Alert and Event O&M. For more information, see Create an alert-triggered O&M task.