Access the Redis Instance from a Redis-cli client
<p>After you create an ECS instance and a whitelist entry, install a Redis-cli client on the ECS instance and access the Redis instance from the Redis-cli client. Redis-cli is the built-in client of Redis. To use Redis-cli, first install Redis.</p>
<p><strong><span style="font-size:18px">Prerequisites</span></strong></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>
</ol>
<p><strong><span style="font-size:18px">Usage Guidelines</span></strong></p>
<p>This article uses a Linux-CentOS ECS instance as an example.</p>
<p><strong><span style="font-size:18px">Procedures</span></strong></p>
<p>1. Log in to the ECS instance.</p>
<p> a. Log in to the <a href="https://pinganyun.com/console/ecs/overview" target="_blank">ECS Console</a>.</p>
<p> b. In the left navigation pane, click <strong>Instance</strong> to enter the <strong>Instance Management</strong> page.</p>
<p> c. In the <strong>Operations</strong> column for the target instance, click <strong>ECS Console</strong>.</p>
<p> d. Enter the username and password.</p>
<p>2. Install Redis.</p>
<p><strong>Method 1:</strong></p>
<p> a. If the operating system of your ECS instance does not include a gcc environment, execute the following command to install gcc:</p>
<pre>
<code>yum install gcc</code></pre>
<p> b. Execute the following command to download the Redis installation package (The download address is <a href="https://redis.io/download" target="_blank">download address</a>):</p>
<pre>
<code>wget http://download.redis.io/releases/redis-5.0.4.tar.gz</code></pre>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507111747-1fa09efe9276.png" style="height:20px; margin:0px; width:80px" />: Choose the Redis version according to your business needs. This article uses Redis 5.0.4 as an example.</p>
<p> c. Execute the following command to decompress the Redis installation package:</p>
<pre>
<code>tar -xzf redis-5.0.4.tar.gz</code></pre>
<p> d. Execute the following command to enter the Redis directory and compile Redis:</p>
<pre>
<code>cd redis-5.0.4
make</code></pre>
<p><strong>Result</strong></p>
<p>The system prompts that the compilation succeeds.</p>
<p><strong>Method 2:</strong></p>
<p> a. If your ECS operating system does not include a gcc environment, execute the following command to install gcc:</p>
<pre>
<code>yum install gcc</code></pre>
<p> b. Execute the following command to install Redis:</p>
<pre>
<code>yum install redis
systemctl start redis
systemctl enable redis</code></pre>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507111932-1436bc5690a3.png" style="height:39px; width:830px" /><strong>Result</strong></p>
<p>Execute the following command to verify the connectivity between the Redis-cli and Redis-server:</p>
<pre>
<code>redis-cli ping</code></pre>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507112025-1e7685199b42.png" style="height:43px; width:485px" /></p>
<p>3. Use the Redis-cli client to access the Redis instance.</p>
<p>Method 1:</p>
<p> a. Execute the following command to enter the src directory:</p>
<pre>
<code>cd src</code></pre>
<p> b. Execute the following command to connect to the Redis instance from the Redis-cli client:</p>
<pre>
<code>./redis-cli -c -h Domain-Name -p Port -a Password</code></pre>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507111747-1fa09efe9276.png" style="height:20px; margin:0px; width:80px" />:</p>
<ul>
<li>Domain-Name: 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>Port: 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>Password: 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.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li>
</ul>
<p>Method 2:</p>
<p>Execute the following command to connect to the Redis instance from the Redis-cli client:</p>
<pre>
<code>redis-cli -h Domain-Name -p Port -a Password</code></pre>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507111747-1fa09efe9276.png" style="height:20px; margin:0px; width:80px" />:</p>
<ul>
<li>Execute the following command to connect to a cluster instance:</li>
</ul>
<pre>
<code>redis-cli -c -h Domain-Name -p Port -a Password</code></pre>
<ul>
<li>Descriptions of parameters are as follows:</li>
</ul>
<p> <strong>Domain-Name</strong>: 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>.</p>
<p> <strong>Port</strong>: 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>.</p>
<p> <strong>Password</strong>: 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.View_Instance" target="_blank">View Basic Information about an Instance</a>.</p>
<p>4. Execute the following command to write data to the Redis instance:</p>
<pre>
<code>set foo bar</code></pre>
<p><strong><span style="font-size:18px">Result</span></strong></p>
<p>Execute the following command to view the newly written data in the Redis instance:</p>
<pre>
<code>get foo</code></pre>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507112556-12f2871a9bcf.png" style="height:110px; width:604px" /> </p>
<p> </p>
<p> </p>
Did the above content solve your problem?
Yes
No
Submitted successfully! Thank you for your feedback, we will try our best to do better and better!