In-depth analysis of Redis memory fragmentation

<p>Let&rsquo;s look at a question first. Assuming that the Redis instance has saved 5GB of data, and now 2GB of data is deleted, will the memory occupied by the Redis process be reduced?</p> <p>The answer is: it may still take up about 5GB of memory, even though the Redis data only takes up about 3GB.</p> <p>If the&nbsp;<code>maxmemory</code>&nbsp;parameter is not set, Redis will not trigger the memory elimination strategy to delete data.</p> <p>Redis will continue to allocate memory for newly written data. Failure to allocate it will cause the application to report an error, but of course, it will not cause downtime.</p> <blockquote> <p>Note:To set the&nbsp;<code>maxmemory</code>&nbsp;parameter, execute the command&nbsp;<code>CONFIG SET maxmemory 100mb</code>, or set&nbsp;<code>maxmemory 100mb</code>&nbsp;in the&nbsp;<code>redis.conf&nbsp;</code>configuration file.</p> </blockquote> <p>You can confirm that the data has been deleted, and use the&nbsp;<code>top</code>&nbsp;command to view it. Why does it still take up so much memory?</p> <p><strong>Where does the freed memory go?</strong></p> <p>When we use the top command to check the system usage, we will find that the memory is still high, and Redis has not really released the memory.</p> <p>Where did all the memory go? At this time, we need to use the&nbsp;<code>info memory</code>&nbsp;command to obtain Redis memory-related indicators.</p> <p><a href="https://levelup.gitconnected.com/in-depth-analysis-of-redis-memory-fragmentation-25eeca1a85a2">Website</a></p>
Tags: Redis Analysis