All Products
Search
Document Center

ApsaraDB for Redis:Step 3: Connect to an ApsaraDB for Redis instance

Last Updated:Jul 05, 2024

This topic describes how to connect to an ApsaraDB for Redis instance by using Data Management (DMS) or redis-cli.

Prerequisites

Procedure

DMS

  1. Log on to the ApsaraDB for Redis console and go to the Instances page. In the top navigation bar, select the region in which the instance that you want to manage resides. Then, find the instance and click the instance ID.

  2. In the upper-right corner of the instance details page, click Log into Database.

  3. In the Log on to Database Instance dialog box, set the Access mode parameter to password login and enter a password.

    In this mode, the default account is used for logon. You can view the account details on the Account Management page in the console.

  4. Click Login.

  5. Write and read data.

    1. On the SQLConsole page in the DMS console, enter the SET foo hello command and click Execute(F8).

      The expected output is OK.

    2. Enter the GET foo command and click Execute(F8).

      The expected output is hello.

redis-cli

In this example, redis-cli is used to connect to a Redis instance from a Linux Elastic Compute Service (ECS) instance that is deployed in the same virtual private cloud (VPC) as the Redis instance.

  1. Log on to the ECS instance and run the following commands in sequence to download, install, and compile redis-cli:

    sudo yum -y install gcc            # Install GNU Compiler Collection (GCC).
    wget https://download.redis.io/releases/redis-7.0.0.tar.gz
    tar xzf redis-7.0.0.tar.gz
    cd redis-7.0.0&&make

    In this example, redis-cli 7.0.0 is used. You can install another version. It takes 2 to 3 minutes to compile and install redis-cli.

  2. Run the following command to connect to the Redis instance:

    src/redis-cli -h hostname -a password -p port

    Parameters:

    • hostname: the endpoint of the Redis instance. In the Connection Information section of the instance details page in the ApsaraDB for Redis console, you can view the VPC endpoint of the instance, such as r-8vbwds91ie1rdl****.redis.zhangbei.rds.aliyuncs.com. For more information, see View endpoints.

    • password: the password of the instance.

    • port: the port number. Default value: 6379.

    Sample command:

    src/redis-cli -h r-8vbwds91ie1rdl****.redis.zhangbei.rds.aliyuncs.com -a TestPassword123 -p 6379
  3. Write and read data.

    1. Run the SET bar foo command.

      The expected output is OK.

    2. Run the GET bar command.

      The expected output is"foo".

References

For more information, see the following topics:

Special connection methods

Common errors and troubleshooting

Error message

Cause and solution

(error) ERR illegal address

The whitelist is incorrectly configured.

  1. Check whether the IP address of your client is added to a whitelist of the ApsaraDB for Redis instance. For more information, see Step 2: Configure whitelists.

  2. Check whether the endpoint of the ApsaraDB for Redis instance is correctly selected. If you connect to the ApsaraDB for Redis instance over the Internet, you must select the public endpoint of the instance. Otherwise, you fail to connect to the ApsaraDB for Redis instance.

  3. Check whether the ECS instance on which your client is deployed is in the same VPC as the ApsaraDB for Redis instance. If not, you must connect to the Tair instance over the Internet.

Then, run the ping endpoint command. If no errors are returned, the client connects to the ApsaraDB for Redis instance. Sample command: ping r-bp1zxszhcgatnx****.redis.rds.aliyuncs.com.

(error) ERR client ip is not in whitelist

Could not connect to Redis

  • (error) ERR invalid password

  • (error) WRONGPASS invalid username-password pair

The password is invalid. Specify the correct password in a valid format. The password format varies with the account type.

  • If you use the default account whose username is the same as the instance ID, enter the password. For example, if the username of the default account is r-bp1zxszhcgatnx**** and the password is Password21, the command to verify the password is AUTH Password21.

  • If you use a custom account, enter the password in the user:password format. For example, if the username of the custom account is testaccount and the password is Rp829dlwa, the command to verify the password is AUTH testaccount:Rp829dlwa.

Note
  • If you use a third-party database management tool such as RDM to connect to your ApsaraDB for Redis instance, specify user:password as the password and leave the username field empty. Otherwise, you fail to connect to the instance.

  • If you forget your password, reset it. For more information, see Change or reset the password.