Get the App
SLTechnology News&Howtos  ›  Servers  › 

[case] redis-server a large number of key expired without freeing up space

Shulou Source: shulou.com Published: 2022-06-03 02:54:00 09月22日 Update

Environment: a redis cluster (the master-slave environment of redis4.0.11)

Background: this redis cluster development has a large number of key writes and expires, resulting in a sharp increase in memory.

After analyzing the rdb file using the rdb tool (git address: https://github.com/sripathikrishnan/redis-rdb-tools), we found that there are a lot of key in memory, and the expiration time is early, but it still exists. Reason: because redis's key cleanup strategy is lazy deletion (lazy free), we can try to increase the number of internal cronjob of redis executed per second, which can speed up key elimination.

Procedure:

1. Config get hz sees that the default value of the current redis-server is 10

2. Config set hz 50 We set hz to 50 here, and then observe it for a period of time (note that the setting value of hz can be gradually increased in steps of 10, but generally no more than 100)

The following two pictures are intercepted by me from the surveillance. You can see that a large number of key have been eliminated quickly after the setup.

Tags: Memory time environment cluster laziness master-slave reason address actual actually tools files times steps strategy background step size analysis attempt development Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi macOS Xiaomi Shulou Technology