Redis Memory Not Releasing Issue and Analysis of 20 Million Expiring Keys
This article describes a Redis 5.0 memory leak scenario where 20 million keys with expiration caused memory not to be released, details the investigation steps, findings about the activeExpireCycle, and concludes that memory will eventually be freed, followed by a promotional announcement for a PHP online live class.
Background: Redis version 5.0 running on a 32 GB cloud server showed continuously increasing memory usage because expired keys were not being released.
Recent operations set expiration times (7‑20 days) on 20 million previously permanent keys.
Optimization process:
Observed Alibaba Cloud “offline full‑key analysis” for several days.
Found memory used by expired keys grew from 2 GB to 5 GB.
Analyzed why memory of expired keys was not released.
Adjusted Redis hz parameter from 10 to 30 with no effect.
Reviewed Redis source code, especially expire.c and the activeExpireCycle function.
Conclusion: Setting expiration on 20 million keys reduced the garbage‑collection hit rate below 25 %, preventing the active expiration cycle from repeatedly scanning expired keys; memory will eventually be freed as more expired keys are encountered.
Final handling: No immediate action required; increasing hz can speed up release but consumes more CPU, as documented by Alibaba Cloud.
Promotional announcement: PHP Chinese website launches the 22nd online live PHP class, offering zero‑basis learning from front‑end to back‑end, live recordings, homework review, and limited‑time gifts for early registrants. Registration via QQ (27220243) or WeChat (phpcn01).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
