forked from docs/doc-exports
Reviewed-by: Liudmila Denisova <ldenisov@noreply.gitea.eco.tsi-dev.otc-service.com> Co-authored-by: chenjunjie <chenjunjie@huawei.com> Co-committed-by: chenjunjie <chenjunjie@huawei.com>
87 lines
16 KiB
HTML
87 lines
16 KiB
HTML
<a name="dcs-ug-0326009"></a><a name="dcs-ug-0326009"></a>
|
|
|
|
<h1 class="topictitle1">Accessing a DCS Redis Instance Through redis-cli</h1>
|
|
<div id="body8662426"><p id="dcs-ug-0326009__en-us_topic_0148195299_p1484772321512">Access a DCS Redis instance through redis-cli on an ECS in the same VPC. For more information on how to use other Redis clients, visit <a href="https://redis.io/clients" target="_blank" rel="noopener noreferrer">https://redis.io/clients</a>.</p>
|
|
<div class="note" id="dcs-ug-0326009__en-us_topic_0148195299_note1453731713365"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="dcs-ug-0326009__ul8962185915398"><li id="dcs-ug-0326009__li149621059133917">The following uses the default port 6379. If you have specified a port, replace 6379 with the actual port.</li><li id="dcs-ug-0326009__li2806183095918"><strong id="dcs-ug-0326009__b72961117192618">When connecting to a Redis Cluster instance, ensure that </strong><strong id="dcs-ug-0326009__b1619020329011">-c</strong><strong id="dcs-ug-0326009__b2029613175269"> is added to the command.</strong> Otherwise, the connection will fail.<ul id="dcs-ug-0326009__ul67372059239"><li id="dcs-ug-0326009__li169104495318">Run the following command to connect to a Redis Cluster instance:<p id="dcs-ug-0326009__p1912912161917"><a name="dcs-ug-0326009__li169104495318"></a><a name="li169104495318"></a>./redis-cli -h <em id="dcs-ug-0326009__i1281121792920">{dcs_instance_address}</em> -p 6379 -a <em id="dcs-ug-0326009__i1339313229292">{password}</em> <strong id="dcs-ug-0326009__b1149122112415">-c</strong></p>
|
|
</li><li id="dcs-ug-0326009__li1628062748">Run the following command to connect to a single-node, master/standby, or Proxy Cluster instance:<p id="dcs-ug-0326009__p191948221115"><a name="dcs-ug-0326009__li1628062748"></a><a name="li1628062748"></a>./redis-cli -h <em id="dcs-ug-0326009__i8857113242912">{dcs_instance_address}</em> -p 6379 -a <em id="dcs-ug-0326009__i6384193642919">{password}</em></p>
|
|
</li></ul>
|
|
<p id="dcs-ug-0326009__p148921956417">For details, see <a href="#dcs-ug-0326009__en-us_topic_0148195299_li1511472544119">3</a> and <a href="#dcs-ug-0326009__en-us_topic_0148195299_li126171140194317">4</a>.</p>
|
|
</li><li id="dcs-ug-0326009__li179872127317">If SSL is enabled for a single-node or master/standby DCS Redis 6.0 instance, set an SSL certificate path.<p id="dcs-ug-0326009__p1489510020592"><a name="dcs-ug-0326009__li179872127317"></a><a name="li179872127317"></a>./redis-cli -h <em id="dcs-ug-0326009__i16769101383016">{dcs_instance_address}</em> -p 6379 -a <em id="dcs-ug-0326009__i557732012302">{password}</em> --tls --cacert <em id="dcs-ug-0326009__i151851244307">{certification file path}</em></p>
|
|
</li><li id="dcs-ug-0326009__li785620464118">If SSL is enabled for a Redis Cluster DCS Redis 6.0 instance, set a certificate path.<p id="dcs-ug-0326009__p124915335592"><a name="dcs-ug-0326009__li785620464118"></a><a name="li785620464118"></a>./redis-cli -h <em id="dcs-ug-0326009__i15530426317">{dcs_instance_address}</em> -p 6379 -a <em id="dcs-ug-0326009__i12218968317">{password}</em> -c --tls --cacert <em id="dcs-ug-0326009__i565061016318">{certification file path}</em></p>
|
|
</li><li id="dcs-ug-0326009__li51841453425">To connect to Redis with SSL encryption, use redis-cli 6.x or later.</li></ul>
|
|
</div></div>
|
|
<div class="section" id="dcs-ug-0326009__en-us_topic_0148195299_section1502270695932"><h4 class="sectiontitle">Prerequisites</h4><ul id="dcs-ug-0326009__en-us_topic_0148195299_ul46828691102415"><li id="dcs-ug-0326009__en-us_topic_0148195299_li7215915117">The DCS Redis instance you want to access is in the <strong id="dcs-ug-0326009__en-us_topic_0148195299_b4219617173719">Running</strong> state.</li><li id="dcs-ug-0326009__en-us_topic_0148195299_li132154114111">An ECS has been created. For more information on how to create ECSs, see the <em id="dcs-ug-0326009__i19836719102317"></em><a href="https://docs.otc.t-systems.com/en-us/usermanual/ecs/en-us_topic_0163572588.html" target="_blank" rel="noopener noreferrer">Elastic Cloud Server User Guide</a>.</li><li id="dcs-ug-0326009__en-us_topic_0148195299_li152161914112">If the ECS runs the Linux OS, ensure that the GCC compilation environment has been installed on the ECS. Run the following command to install GCC if needed:<pre class="screen" id="dcs-ug-0326009__screen55587413567">yum install -y make
|
|
yum install -y pcre-devel
|
|
yum install -y zlib-devel
|
|
yum install -y libevent-devel
|
|
yum install -y openssl-devel
|
|
yum install -y gcc-c++</pre>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="dcs-ug-0326009__en-us_topic_0148195299_section596432855917"><h4 class="sectiontitle">Procedure (Linux)</h4><ol id="dcs-ug-0326009__en-us_topic_0148195299_ol9211121417287"><li id="dcs-ug-0326009__en-us_topic_0148195299_li5799181918288"><a name="dcs-ug-0326009__en-us_topic_0148195299_li5799181918288"></a><a name="en-us_topic_0148195299_li5799181918288"></a><span>View the IP address/domain name and port number of the DCS Redis instance to be accessed.</span><p><p id="dcs-ug-0326009__en-us_topic_0148195299_p17805111982815">For details, see <a href="dcs-ug-0312016.html">Viewing and Modifying DCS Instance Information</a>.</p>
|
|
</p></li><li id="dcs-ug-0326009__en-us_topic_0148195299_li74512146382"><span>Install redis-cli.</span><p><p id="dcs-ug-0326009__en-us_topic_0148195299_p89239583388">The following steps assume that your client is installed on the Linux OS.</p>
|
|
<ol type="a" id="dcs-ug-0326009__en-us_topic_0148195299_ol1022615177396"><li id="dcs-ug-0326009__en-us_topic_0148195299_li11557181043917">Log in to the ECS.</li><li id="dcs-ug-0326009__en-us_topic_0148195299_li1155831053920">Run the following command to download the source code package of your Redis client from <a href="http://download.redis.io/releases/redis-5.0.8.tar.gz" target="_blank" rel="noopener noreferrer">https://download.redis.io/releases/redis-6.2.13.tar.gz</a>:<p id="dcs-ug-0326009__en-us_topic_0148195299_p5558151033916"><strong style="color:#36383C;" id="dcs-ug-0326009__en-us_topic_0148195299_b055831013919">wget http://download.redis.io/releases/redis-6.2.13.tar.gz</strong></p>
|
|
<div class="note" id="dcs-ug-0326009__note0851740193017"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dcs-ug-0326009__p18529402305">The following uses redis-6.2.13 as an example. For details, see the <a href="https://redis.io/download?spm=a2c4g.11186623.2.15.4e732074zS4LSS#installation" target="_blank" rel="noopener noreferrer">Redis official website</a>.</p>
|
|
</div></div>
|
|
</li><li id="dcs-ug-0326009__en-us_topic_0148195299_li145586109393">Run the following command to decompress the source code package of your Redis client:<p id="dcs-ug-0326009__en-us_topic_0148195299_p255861013918"><a name="dcs-ug-0326009__en-us_topic_0148195299_li145586109393"></a><a name="en-us_topic_0148195299_li145586109393"></a><strong id="dcs-ug-0326009__en-us_topic_0148195299_b3558810123910">tar -xzf <span style="color:#36383C;">redis-6.2.13.tar.gz</span></strong></p>
|
|
</li><li id="dcs-ug-0326009__en-us_topic_0148195299_li5558131033913">Run the following commands to go to the Redis directory and compile the source code of your Redis client:<p id="dcs-ug-0326009__en-us_topic_0148195299_p125581101396"><a name="dcs-ug-0326009__en-us_topic_0148195299_li5558131033913"></a><a name="en-us_topic_0148195299_li5558131033913"></a><strong id="dcs-ug-0326009__en-us_topic_0148195299_b3559111015392">cd redis-6.2.13</strong></p>
|
|
<p id="dcs-ug-0326009__en-us_topic_0148195299_p355971003910"><strong id="dcs-ug-0326009__en-us_topic_0148195299_b03266284391">cd src</strong></p>
|
|
<p id="dcs-ug-0326009__p8879143510432"><strong id="dcs-ug-0326009__en-us_topic_0148195299_b185590101399">make</strong></p>
|
|
<p id="dcs-ug-0326009__p158631940144317"><strong id="dcs-ug-0326009__b168531155104614">make install</strong></p>
|
|
</li></ol>
|
|
</p></li><li id="dcs-ug-0326009__en-us_topic_0148195299_li1511472544119"><a name="dcs-ug-0326009__en-us_topic_0148195299_li1511472544119"></a><a name="en-us_topic_0148195299_li1511472544119"></a><span>Access a DCS instance of a type other than Redis Cluster.</span><p><p id="dcs-ug-0326009__en-us_topic_0148195299_p10196194418415">Perform the following procedure to access a single-node, master/standby, read/write splitting, or Proxy Cluster instance.</p>
|
|
<p id="dcs-ug-0326009__p112171018503"><strong id="dcs-ug-0326009__b181815500375">./redis-cli -h $<em id="dcs-ug-0326009__i1384014221614">{dcs_instance_address}</em> -p 6379 -a $<em id="dcs-ug-0326009__i83717268616">{password}</em></strong></p>
|
|
<div class="note" id="dcs-ug-0326009__note1721191325012"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ol type="a" id="dcs-ug-0326009__ol158735372514"><li id="dcs-ug-0326009__li4587753132516">If the instance is password-free, connect it by running the<strong id="dcs-ug-0326009__b1821551022715"> ./redis-cli -h </strong><em id="dcs-ug-0326009__i42159103276">${dcs_instance_address}</em><strong id="dcs-ug-0326009__b6215181017279"> -p 6379</strong> command.</li><li id="dcs-ug-0326009__li125871253192518">If the instance is password-protected, connect it by running the <strong id="dcs-ug-0326009__b5569165119395">./redis-cli -h </strong><em id="dcs-ug-0326009__i1050845013391">${dcs_instance_address}</em><strong id="dcs-ug-0326009__b937895917393"> -p 6379 -a </strong><em id="dcs-ug-0326009__i680915903914">${password}</em> command.</li><li id="dcs-ug-0326009__li11509414718"><em id="dcs-ug-0326009__i59691822105317">{dcs_instance_address}</em> can be the <strong id="dcs-ug-0326009__b1344010129255">Connection Address</strong> (domain name) or <strong id="dcs-ug-0326009__b1530015922414">IP Address</strong>. For details, see <a href="dcs-faq-022025.html">Should I Use Domain Name or IP Address to Connect to a Redis Instance?</a>.<p id="dcs-ug-0326009__p2172132910101"><span><img id="dcs-ug-0326009__image1917232913100" src="en-us_image_0000001538860065.png"></span></p>
|
|
</li></ol>
|
|
</div></div>
|
|
</p></li><li id="dcs-ug-0326009__en-us_topic_0148195299_li126171140194317"><a name="dcs-ug-0326009__en-us_topic_0148195299_li126171140194317"></a><a name="en-us_topic_0148195299_li126171140194317"></a><span>Access a DCS instance of the Redis Cluster type.</span><p><p id="dcs-ug-0326009__en-us_topic_0148195299_p106170401437">Do as follows to access a Redis Cluster instance:</p>
|
|
<ol type="a" id="dcs-ug-0326009__en-us_topic_0148195299_ol19617184018436"><li id="dcs-ug-0326009__en-us_topic_0148195299_li461774013434">Run the following commands to access the chosen DCS Redis instance:<p id="dcs-ug-0326009__en-us_topic_0148195299_p1943564413440"><a name="dcs-ug-0326009__en-us_topic_0148195299_li461774013434"></a><a name="en-us_topic_0148195299_li461774013434"></a><strong id="dcs-ug-0326009__en-us_topic_0148195299_b105815143619">./redis-cli -h <em id="dcs-ug-0326009__i17352264516">{dcs_instance_address}</em> -p 6379 -a <em id="dcs-ug-0326009__i89107302459">{password}</em> -c</strong></p>
|
|
<p id="dcs-ug-0326009__en-us_topic_0148195299_p1561884084317"><em id="dcs-ug-0326009__i10720151231517">{dcs_instance_address}</em> indicates the IP address/domain name of the DCS Redis instance, <span class="parmname" id="dcs-ug-0326009__parmname372191211155"><b>6379</b></span> is the port used for accessing the instance, <em id="dcs-ug-0326009__i1272151291519">{password}</em> is the password of the instance, and <strong id="dcs-ug-0326009__b197211712131514">-c</strong> is used for accessing Redis Cluster nodes. The IP address/domain name and port number are obtained in <a href="#dcs-ug-0326009__en-us_topic_0148195299_li5799181918288">1</a>.</p>
|
|
<div class="p" id="dcs-ug-0326009__p207814105325">Example:<pre class="screen" id="dcs-ug-0326009__en-us_topic_0148195299_screen121171038171515">root@ecs-redis:~/redis-6.2.13/src# ./redis-cli -h 192.168.0.85 -p 6379 -a ****** -c
|
|
192.168.0.85:6379> </pre>
|
|
</div>
|
|
</li><li id="dcs-ug-0326009__en-us_topic_0148195299_li6858275534">Run the following command to view the Redis Cluster node information:<p id="dcs-ug-0326009__en-us_topic_0148195299_p8961923145318"><a name="dcs-ug-0326009__en-us_topic_0148195299_li6858275534"></a><a name="en-us_topic_0148195299_li6858275534"></a><strong id="dcs-ug-0326009__en-us_topic_0148195299_b61371215105419">cluster nodes</strong></p>
|
|
<p id="dcs-ug-0326009__en-us_topic_0148195299_p4437193213552">Each shard in a Redis Cluster has a master and a replica by default. The proceeding command provides all the information of cluster nodes.</p>
|
|
<pre class="screen" id="dcs-ug-0326009__en-us_topic_0148195299_screen63868345412">192.168.0.85:6379> cluster nodes
|
|
0988ae8fd3686074c9afdcce73d7878c81a33ddc 192.168.0.231:6379@16379 slave f0141816260ca5029c56333095f015c7a058f113 0 1568084030
|
|
000 3 connected
|
|
1a32d809c0b743bd83b5e1c277d5d201d0140b75 192.168.0.85:6379@16379 myself,master - 0 1568084030000 2 connected 5461-10922
|
|
c8ad7af9a12cce3c8e416fb67bd6ec9207f0082d 192.168.0.130:6379@16379 slave 1a32d809c0b743bd83b5e1c277d5d201d0140b75 0 1568084031
|
|
000 2 connected
|
|
7ca218299c254b5da939f8e60a940ac8171adc27 192.168.0.22:6379@16379 master - 0 1568084030000 1 connected 0-5460
|
|
f0141816260ca5029c56333095f015c7a058f113 192.168.0.170:6379@16379 master - 0 1568084031992 3 connected 10923-16383
|
|
19b1a400815396c6223963b013ec934a657bdc52 192.168.0.161:6379@16379 slave 7ca218299c254b5da939f8e60a940ac8171adc27 0 1568084031
|
|
000 1 connected</pre>
|
|
<p id="dcs-ug-0326009__en-us_topic_0148195299_p9772152455814"></p>
|
|
<p id="dcs-ug-0326009__en-us_topic_0148195299_p5681531165611">Write operations can only be performed on master nodes. The CRC16 of the key modulo 16384 is taken to compute what is the hash slot of a given key.</p>
|
|
<p id="dcs-ug-0326009__en-us_topic_0148195299_p1624614082619">As shown in the following, the value of <strong id="dcs-ug-0326009__en-us_topic_0148195299_b16284172116488">CRC16 (KEY) mod 16384</strong> determines the hash slot that a given key is located at and redirects the client to the node where the hash slot is located at.</p>
|
|
<pre class="screen" id="dcs-ug-0326009__en-us_topic_0148195299_screen9405318316">192.168.0.170:6379> set hello world
|
|
-> Redirected to slot [866] located at 192.168.0.22:6379
|
|
OK
|
|
192.168.0.22:6379> set happy day
|
|
OK
|
|
192.168.0.22:6379> set abc 123
|
|
-> Redirected to slot [7638] located at 192.168.0.85:6379
|
|
OK
|
|
192.168.0.85:6379> get hello
|
|
-> Redirected to slot [866] located at 192.168.0.22:6379
|
|
"world"
|
|
192.168.0.22:6379> get abc
|
|
-> Redirected to slot [7638] located at 192.168.0.85:6379
|
|
"123"
|
|
192.168.0.85:6379> </pre>
|
|
</li></ol>
|
|
</p></li></ol>
|
|
</div>
|
|
<div class="section" id="dcs-ug-0326009__en-us_topic_0148195299_section0560105823710"><h4 class="sectiontitle">Procedure (Windows)</h4><p id="dcs-ug-0326009__en-us_topic_0148195299_p8663185612015"><a href="https://github.com/MicrosoftArchive/redis/tags" target="_blank" rel="noopener noreferrer">Download</a> the compilation package of the Redis client for Windows. (This is not the source code package.) Decompress the package in any directory, open the CLI tool <strong id="dcs-ug-0326009__en-us_topic_0148195299_b203671953114013">cmd.exe</strong>, and go to the directory. Then, run the following command to access the DCS Redis instance:</p>
|
|
<p id="dcs-ug-0326009__en-us_topic_0148195299_p1266319562200"><strong id="dcs-ug-0326009__b5913615010">redis-cli.exe -h <em id="dcs-ug-0326009__i11887142710914">XXX</em> -p <em id="dcs-ug-0326009__i34247113013">6379</em></strong></p>
|
|
<p id="dcs-ug-0326009__en-us_topic_0148195299_p46634560206"><span class="parmname" id="dcs-ug-0326009__parmname8714742814"><b>XXX</b></span> indicates the IP address/domain name of the DCS instance and <span class="parmname" id="dcs-ug-0326009__parmname888478283"><b>6379</b></span> is an example port number used for accessing the DCS instance. For details about how to obtain the IP address/domain name and port number, see <a href="dcs-ug-0312016.html">Viewing and Modifying DCS Instance Information</a>. Change the address and port as required.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dcs-ug-0916002.html">Accessing an Instance</a></div>
|
|
</div>
|
|
</div>
|
|
|