Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Accessing a DCS Redis Instance Through redis-cli

Updated on 2022-02-21 GMT+08:00

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 https://redis.io/clients.

NOTE:
  • Redis 3.0 does not support port customization and allows only port 6379. For Redis 4.0 and 5.0, you can specify a port or use the default port 6379. The following uses the default port 6379. If you have specified a port, replace 6379 with the actual port.
  • When connecting to a Redis Cluster instance, ensure that -c is added to the command. Otherwise, the connection will fail.
    • Run the following command to connect to a Redis Cluster instance:

      ./redis-cli -h {dcs_instance_address} -p 6379 -a {password} -c

    • Run the following command to connect to a single-node, master/standby, or Proxy Cluster instance:

      ./redis-cli -h {dcs_instance_address} -p 6379 -a {password}

    For details, see 3 and 4.

Prerequisites

  • The DCS Redis instance you want to access is in the Running state.
  • An ECS has been created. For more information on how to create ECSs, see the Elastic Cloud Server User Guide.
  • If the ECS runs the Linux OS, ensure that the GCC compilation environment has been installed on the ECS.

Procedure (Linux)

  1. Obtain the IP address and port number of the DCS Redis instance to be accessed.

    For details, see Viewing Details of a DCS Instance.

  2. Install redis-cli.

    The following steps assume that your client is installed on the Linux OS.

    1. Log in to the ECS.
    2. Run the following command to download the source code package of your Redis client from http://download.redis.io/releases/redis-3.0.7.tar.gz:

      wget http://download.redis.io/releases/redis-3.0.7.tar.gz

    3. Run the following command to decompress the redis-3.0.7 directory from the package:

      tar -xzf redis-3.0.7.tar.gz

    4. Run the following commands to go to the redis-3.0.7 directory and compile the source code of your Redis client:

      cd redis-3.0.7

      make

      cd src

  3. Access a DCS instance of a type other than Redis Cluster.

    Perform the following procedure to access a DCS Redis 3.0 instance, or a single-node or master/standby DCS Redis 4.0 or 5.0 instance.

    1. Run the following commands to access the chosen DCS Redis instance:

      ./redis-cli -h {dcs_instance_address} -p 6379

      {dcs_instance_address} indicates the IP address of the DCS instance and 6379 is the port used for accessing the instance. The IP address and port number are obtained in 1.

      Example:

      [root@ecs-redis redis-3.0.7]# cd src
      [root@ecs-redis src]# ./redis-cli -h 192.168.0.148 -p 6379
      192.168.0.148:6379> 
    2. Enter the password. You can read and write cached data only after the password is verified.

      auth <password>

      <password> indicates the password used for logging in to the chosen DCS Redis instance. This password is defined during DCS Redis instance creation.

      The command output is as follows:

      192.168.0.148:6379> auth *******
      OK
      192.168.0.148:6379> 

  4. Access a DCS instance of the Redis Cluster type.

    Perform the following procedure to access a DCS Redis 4.0 or 5.0 instance in Redis Cluster type.

    1. Run the following commands to access the chosen DCS Redis instance:

      ./redis-cli -h {dcs_instance_address} -p 6379 -a {password} -c

      {dcs_instance_address} indicates the IP address of the DCS Redis instance, 6379 is the port used for accessing the instance, {password} is the password of the instance, and -c is used for accessing Redis Cluster nodes. The IP address and port number are obtained in 1.

      Example:
      root@ecs-redis:~/redis-3.0.7/src# ./redis-cli -h 192.168.0.85 -p 6379 -a ****** -c
      192.168.0.85:6379> 
    2. Run the following command to view the Redis Cluster node information:

      cluster nodes

      Each shard in a Redis Cluster has a master and a replica by default. The proceeding command provides all the information of cluster nodes.

      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

      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.

      As shown in the following, the value of CRC16 (KEY) mode 16384 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.

      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> 

Procedure (Windows)

Download the Windows Redis client installation package. Decompress the package, open the CLI tool cmd.exe, and go to the directory where the decompressed Redis client installation package is saved. Then, run the following command to access the DCS Redis instance:

redis-cli -h XXX -p 6379

XXX indicates the IP address of the DCS instance and 6379 is an example port number used for accessing a DCS instance. For details on how to obtain the IP address and port, see Viewing Details of a DCS Instance. Change the IP address and port as required.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback