All Products
Search
Document Center

Tair (Redis® OSS-Compatible):Clear expired keys

Last Updated:Mar 27, 2026

Tair (Redis OSS-compatible) automatically removes expired keys through three built-in policies. When key counts grow unexpectedly despite expiration settings—or a large batch of keys (tens to hundreds of thousands) expires within a short window—the built-in policies may not clear them fast enough. This page explains how automatic expiry works and what you can do to speed up the cleanup.

How it works

Tair uses three policies to clear expired keys automatically. No manual action is required for any of them.

Passive expiry

When a client accesses a key, Tair checks whether it has expired. If it has, Tair deletes it immediately. Passive expiry is lightweight but only runs on keys that are actually accessed—keys that are never read again stay in memory until something else removes them.

Active expiry

Because passive expiry alone cannot handle keys that are never accessed again, Tair periodically samples keys with expiration times and deletes those that have already expired.

Forcible eviction

When memory usage reaches the maxmemory limit, Tair blocks operations, evicts keys, or raises an out-of-memory (OOM) error. By default, it uses the volatile-lru policy.

To review or change the eviction policy, see the maxmemory-policy parameter in Supported parameters.

Clear expired keys faster

The following methods speed up expired key cleanup. Choose based on your situation.

Use Purge Data for immediate cleanup

The Purge Data feature on the instance details page deletes all expired keys in the shortest possible time.

Warning

This operation consumes significant instance resources and may affect running workloads. Run it during off-peak hours.

For instructions, see Purge data.

Schedule cleanup with CloudOps Orchestration Service

Use CloudOps Orchestration Service (OOS) to schedule a recurring O&M task that deletes expired keys during off-peak hours. This avoids resource spikes during business hours.

For instructions, see Periodically delete expired keys.

Increase the active expiry frequency

The hz parameter controls how often Tair runs its background tasks, including active expiry. Increasing hz causes Tair to sample and delete expired keys more frequently.

Important

A higher hz value increases CPU consumption. Raise the value in increments of 10 and monitor CPU utilization after each change to avoid overloading the instance.

For instructions, see Enable dynamic frequency control for background tasks.

Set TTLs on keys

If your keys have no expiration time set, they accumulate indefinitely. Assign a time-to-live (TTL) to keys based on how long the data is actually needed. This prevents long-term storage of stale data and reduces the chance of future accumulation.

What's next

References