Memory Analysis

<p>This article describes how to view the memory usage of a Redis instance through a Redis client.</p> <p><strong><span style="font-size:18px">Overview</span></strong></p> <p>You can view the memory usage ratio in the Argus console to calculate the current memory usage. You can also analyze the rbd file of the target Redis instance by using redis-rdb-tools to obtain the detailed memory usage information of the instance.</p> <p>For Redis 4.0 and higher, you can use the <code>memory </code>command to analyze the memory space used by a specific key.</p> <p><strong><span style="font-size:18px">View the Memory Usage of a Redis Instance</span></strong></p> <p><span style="font-size:16px"><strong>Prerequisites</strong></span></p> <ol> <li>You have successfully created a Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_Redis" target="_blank">Create a Redis Instance</a>. Make sure the instance is in running status.</li> <li>You have successfully created an ECS instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_ECS" target="_blank">Create an ECS Instance</a>. Make sure the instance is in running status.</li> <li>You have successfully created a whitelist entry. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_Whitelist" target="_blank">Create a Whitelist Entry</a>.</li> <li>You have successfully installed a Redis client on the ECS instance. For more information, see Access the Redis Instance. This article uses the Redis-cli client as an example. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Connect_Redis.Redis_cli" target="_blank">Access the Redis Instance from a Redis-cli client</a>.</li> </ol> <p><span style="font-size:16px"><strong>Procedures</strong></span></p> <p>1.&nbsp;&nbsp;&nbsp;&nbsp; Install redis-rdb-tools.</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; a.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Execute the following command to download the redis-rdb-tools installation package:</p> <pre> <code>wget https://github.com/sripathikrishnan/redis-rdb-tools/archive/rdbtools-0.1.14.tar.gz</code></pre> <p>&nbsp; &nbsp; &nbsp; &nbsp; b.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Execute the following command to decompress the redis-rdb-tools installation package:</p> <pre> <code>tar –xzf rdbtools-0.1.14.tar.gz</code></pre> <p>&nbsp; &nbsp; &nbsp; &nbsp; c.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Execute the following command to enter the redis-rdb-tools directory:</p> <pre> <code>cd redis-rdb-tools-rdbtools-0.1.14</code></pre> <p>&nbsp; &nbsp; &nbsp; &nbsp; d.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Execute the following command to install redis-rdb-tools:</p> <pre> <code>sudo python setup.py install</code></pre> <p><span style="font-size:14px"><strong>&nbsp; &nbsp; &nbsp; &nbsp;Result</strong></span></p> <p>&nbsp; &nbsp; &nbsp; &nbsp; Execute the following command to view the Python version.</p> <pre> <code>python --version</code></pre> <p>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Install PyPI. For more information, go to https://pip.pypa.io/en/stable/installing/.</p> <pre> <code>wget https://bootstrap.pypa.io/get-pip.py python get-pip.py</code></pre> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507161421-18aa25249081.png" style="height:20px; margin:0px; width:80px" />: For Python 2 versions Python 2.7.9 and later, and Python 3 versions Python 3.4 and later, you do not need to install PyPI because they have built-in PyPI.</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>Result</strong></p> <p>&nbsp; &nbsp; &nbsp; &nbsp;Execute the following command to view the installed pip version.</p> <pre> <code>pip --version</code></pre> <p>3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Configure the editing environment:</p> <pre> <code>yum install gcc libffi-devel python-devel openssl-devel -y pip install python-lzf</code></pre> <p>4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Execute the following command to obtain the rdb file of the target Redis instance and save it to the <strong>test.rdb</strong> file in the current path:</p> <pre> <code>./redis-cli -h Domain-name -p Port -a Password --rdb test.rdb</code></pre> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507161421-18aa25249081.png" style="height:20px; margin:0px; width:80px" />:</p> <ul> <li><em>Domain-Name</em>: Access domain name of the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li> <li><em>Port</em>: Port number of the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li> <li><em>Password</em>: Password of the Redis instance that has been set when you create the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.Create_Instance" target="_blank">Create an Instance</a> and <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li> </ul> <p>5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Use redis-rdb-tools to analyze the target rbd file <strong>test.rdb</strong>, and save the analysis result to the <strong>memory.csv</strong> file.</p> <pre> <code>rdb -c memory rdb.test &gt; memory.csv</code></pre> <p><span style="font-size:16px"><strong>Result</strong></span></p> <p>Execute the <code>cat memoyt.csv</code> command to view the memory usage of the target Redis instance.</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507161810-1313aa7b9d7b.png" style="height:139px; width:967px" /></p> <p><strong><span style="font-size:18px">View the Memory Usage of a Key</span></strong></p> <p><span style="font-size:16px"><strong>Prerequisites</strong></span></p> <p>You have successfully accessed a Redis instance from a Redis client. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Map" target="_blank">Quick Start</a>.</p> <p><span style="font-size:16px"><strong>Usage Guidelines</strong></span></p> <p>Make sure your Redis instance version is 4.0 or higher.</p> <p><span style="font-size:16px"><strong>Procedures</strong></span></p> <ol> <li>Install a Redis client. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Connect_Redis.Redis_cli" target="_blank">Access the Redis Instance</a>.</li> <li>Log in to a Redis instance. Execute the following command to view the memory usage of a key:</li> </ol> <pre> <code>MEMORY USAGE key</code></pre> <p><span style="font-size:16px"><strong>Result</strong></span></p> <p>The memory usage of the key is displayed.</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507162044-16ef023298d5.png" style="height:71px; width:497px" /></p> <p>&nbsp;</p>
Did the above content solve your problem? Yes No
Please complete information!

Call us

400-151-8800

Email us

cloud@pingan.com

Online customer service

Instant reply

Technical Support

cloud products