This topic describes the default policies for automatically clearing expired keys and the methods for manually clearing expired keys in Tair (Redis OSS-compatible).
Background information
If your instance has data expiration policies in place but the number of keys in the instance is significantly greater than expected, or if a large number of keys (such as tens or hundreds of thousands) expire at a specific time point or within a specific time range (such as one to two hours), your instance may contain excessive expired keys to be deleted.
Default policies
Tair (Redis OSS-compatible) provides the following default policies to automatically clear expired keys:
Active expiry: The system regularly detects and clears expired keys.
Passive expiry: When you access an expired key, the system clears the key.
Forcible eviction: When the memory usage of an instance reaches the
Maxmemory
value, operations are blocked, keys are evicted, or an out of memory (OOM) error is triggered. In this case, Redis uses thevolatile-lru
policy. For more information, see themaxmemory-policy
parameter in the Supported parameters topic.
The preceding policies involve no manual operations.
Quickly clear expired keys
The following section describes different methods to quickly clear expired keys:
Use the Clear Data feature on the instance details page of the console to quickly remove all expired keys from the instance. For more information, see Clear data.
WarningThis method takes the least amount of time but consumes more instance resources. This may affect your online business. Proceed with caution. We recommend that you perform this operation during off-peak hours.
Set
hz
to a greater value to clear expired keys more frequently. For more information, see Enable dynamic frequency control for background tasks.ImportantThe greater the value is, the more CPU resources the instance consumes.
We recommend that you increase the value in increments of 10 and observe the CPU utilization of the instance to prevent excessive loads on the CPU.
Configure a time-to-live (TTL) expiration policy for keys based on your needs to prevent long-term storage of irrelevant keys in your database.
References
Applicable scope
Tair (Redis OSS-compatible)