Help Center/ Distributed Cache Service/ Getting Started/ Getting Started with Redis and Reading and Writing Data Using Web CLI
Updated on 2024-11-18 GMT+08:00

Getting Started with Redis and Reading and Writing Data Using Web CLI

This section takes the example of creating a single-node Distributed Cache Service (DCS) Redis 5.0 instance, connecting to it, and performing data read and write operations on the DCS console to get you quickly started with DCS.

There are three steps to get started with DCS:

  1. Preparations

    Before creating a Redis instance, an authenticated Huawei Cloud account with balance, users with required permissions, and a set of VPC and subnet should be prepared.

  2. Creating a DCS Redis Instance

    When creating a Redis instance, you can customize it with the required type and specifications, and configure a VPC and a subnet.

  3. Accessing a Redis Instance and Reading and Writing Data

    Access Redis instances and run Redis commands to read and write data on a client compatible with Redis or using Web CLI on the DCS console.

Preparations

  1. Register a Huawei Cloud account and authenticate it.
    If you already have one, go to 2. If you do not have one, do as follows:
    1. Log in to the Huawei Cloud official website, and click Register.
    2. Complete the registration as prompted. For details, see Signing up for a HUAWEI ID and Enabling Huawei Cloud Services.

      Your personal information page is displayed after the registration completes.

    3. Complete real-name authentication for individual or enterprise users by referring to Real-Name Authentication.

      Real-name authentication is required only when you buy or use resources in the Chinese mainland.

  2. Top up your account.

    Ensure enough balance in your account.

  3. Add DCS permissions.

    Before creating a Redis instance and its dependencies, specific permissions are required. For details about how to add user permissions, see Creating a User and Granting DCS Permissions.

  4. Create a VPC and a subnet.

    A DCS instance runs in a virtual private cloud (VPC) and has a subnet. Prepare a VPC and a subnet before creating a DCS instance. For more information, see Creating a VPC. If you already have an available VPC and subnet, use them.

    • The VPC must be created in the same region as your DCS Redis instance.
    • In VPC and subnet creation, retain the default settings unless otherwise specified.

Creating a DCS Redis Instance

  1. Go to the Buy DCS Instance page.
  2. Select Custom.
  3. Configure the instance. For details, see Table 1.

    Table 1 Configuring an instance

    Parameter

    Description

    Billing Mode

    Select Pay-per-use.

    Region

    Retain the default setting.

    Project

    Retain the default setting.

    Cache Engine

    This example uses Redis.

    Edition

    This example uses Basic.

    CPU Architecture

    This example uses x86.

    Version

    Select 5.0 in this operation.

    Instance Type

    Select Single-node in this operation. Single-node Redis instances use single nodes, do not persist data, and cost low. They are applicable in development and testing.

    AZ

    Each region contains multiple AZs. This example retains the default AZ.

    Instance Specification

    Select 128 MB in this operation.

    VPC

    Select the VPC in Preparations.

    Subnet

    Select the subnet in Preparations.

    IPv4 Address

    Auto and Manual are available.

    In this example, select Auto.

    Port

    Custom. The default port 6379 will be used when unspecified.

    In this example, use 6379.

    Security Group

    Skip it.

    Instance Name

    By default, a random name is generated. Retain it.

    Enterprise Project

    An enterprise project manages cloud resources by gathering relevant ones together. The default option default is available.

    If you cannot select a required enterprise project, see Why Can't I Select the Required Enterprise Project When Creating a DCS Instance?

    Password Protected

    Select Yes and enter Password and Confirm Password.

    (Optional) Advanced Settings

    In this example, you can skip these settings.

    Quantity

    One instance will be created by default, and you can buy up to 100 DCS instances at a time.

  4. Check the estimated price in the lower left corner of the page. You can click Pricing details to learn more.
  5. Click Next.
  6. Confirm the instance settings, and click Submit.

    The instance has been created successfully if it is in the Running state.

  7. After the task is successfully submitted, the Cache Manager page is displayed. When the new instance is in the Running state, the instance is created successfully.

Accessing a Redis Instance and Reading and Writing Data

This section takes the example of accessing a DCS Redis instance by using Web CLI on the console.

To access a DCS Redis instance on a compatible client, see Accessing Redis on a Client.

  1. In the navigation pane, choose Cache Manager. In the Operation column of the instance, choose More > Connect to Redis, as shown in the following figure.

    Figure 1 Accessing Web CLI

  2. Enter the password set in instance creation and go to Web CLI.

    • If no operation is performed for more than 5 minutes, the connection times out. You need to enter the password to access the instance again.
    • You do not need to enter a password for accessing a password-free DCS Redis instance.

  3. Single-node instances support multiple databases (multi-DB). Select one of the databases. Select "Database 0" here.

    Figure 2 Selecting a Database

  4. Enter Redis commands in the input box. For example, run the SET command to write a data name KEY_NAME and data value VALUE, and press Enter. The data is written when "OK" is returned. Write another ABC data of 123 again.

    > SET KEY_NAME VALUE
      OK
    > SET ABC 123
      OK

  5. Run the GET command to read the written data.

    > GET KEY_NAME
      VALUE
    > GET ABC
      123

Related Information