In-depth analysis of Redis memory fragmentation
<p>Let’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 <code>maxmemory</code> 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 <code>maxmemory</code> parameter, execute the command <code>CONFIG SET maxmemory 100mb</code>, or set <code>maxmemory 100mb</code> in the <code>redis.conf </code>configuration file.</p>
</blockquote>
<p>You can confirm that the data has been deleted, and use the <code>top</code> 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 <code>info memory</code> 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>