ApsaraDB for Redis provides multiple endpoint types and allows you to connect to an instance over a Virtual Private Cloud (VPC) or the Internet. You can connect to an instance by using Data Management (DMS), redis-cli, or a client.

Endpoint types

By default, you can connect to a ApsaraDB for Redis instance over VPC.If you want to connect to your ApsaraDB for Redis instance from your on-premises device or other devices over the Internet, apply for a public endpoint for the ApsaraDB for Redis instance.

  • If your client is deployed on an ECS instance in the same VPC as your ApsaraDB for Redis instance, we recommend that you connect to the ApsaraDB for Redis instance over the VPC by using a private endpoint. This improves security and reduces network latency.
  • If your client is deployed on an on-premises device or an ECS instance that resides in a different region and a different VPC from your ApsaraDB for Redis instance, you can connect to the ApsaraDB for Redis instance over the Internet by using a public endpoint. Otherwise, you fail to connect to the ApsaraDB for Redis instance.

Prerequisites

  • The public IP address of your client is added to a whitelist of the ApsaraDB for Redis instance.

    Before you can connect to your ApsaraDB for Redis instance over a VPC or the Internet, you must add the IP address or CIDR block of your client to a whitelist of the ApsaraDB for Redis instance. For more information, see Step 2: Configure whitelists.

  • The username and password of an account are set to connect to the ApsaraDB for Redis instance.

    You can connect to your ApsaraDB for Redis instance by using a default or custom account. For more information, see Access an ApsaraDB for Redis instance.

Procedure

In this example, redis-cli is used to establish a connection between an Elastic Compute Service (ECS) instance that runs on the Linux operating system and an ApsaraDB for Redis instance over a VPC.

  1. Log on to the ECS instance. Then, download and install redis-cli.
    1. Run the following command to download the Redis source code package:
      wget https://download.redis.io/releases/redis-6.0.9.tar.gz
      Note Redis 6.0.9 is used in this example to demonstrate the operations. You can install other versions. For more information, visit Redis.
    2. Run the following command to decompress the Redis source code package:
      tar xzf redis-6.0.9.tar.gz
    3. Run the following command to go to the directory to which the Redis source code package is decompressed. Then, compile and install Redis.
      cd redis-6.0.9&&make
      It takes 2 or 3 minutes to compile and install Redis.
  2. Obtain the connection information and run the following command in redis-cli to connect to the ApsaraDB for Redis instance:
    redis-cli -h hostname -p port [-c]
    Table 1. Parameters
    Parameter Description Method to obtain the parameter value
    hostname The endpoint of the ApsaraDB for Redis instance.
    • If you connect to the ApsaraDB for Redis instance over a VPC, obtain the endpoint of the instance in the VPC.
    • If you connect to the ApsaraDB for Redis instance over the Internet, obtain the public endpoint of the instance.
    For more information, see View endpoints.
    port The port number of the ApsaraDB for Redis instance. The default port number is 6379.
    -c Specifies whether to enable the cluster mode.

    The cluster mode is available only if the ApsaraDB for Redis instance is a cluster instance that uses a private endpoint. For more information, see Cluster master-replica instances and Enable the direct connection mode.

    Examples:
    • The following sample command is suitable for scenarios where Tair instances are connected by using default endpoints, such as endpoints of standard instances and proxy endpoints of cluster instances:
      redis-cli -h r-bp1zxszhcgatnx****.redis.rds.aliyuncs.com -p 6379
    • The following sample command is suitable for scenarios where Tair cluster instances are connected by using private endpoints:
      redis-cli -h r-bp1zxszhcgatnx****.redis.rds.aliyuncs.com -p 6379 -c
  3. Run the following command to verify the password:
    AUTH password
    Table 2. Parameters
    Parameter Description
    password
    The password of the account.
    • 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 forget the password or have not set a password, you can reset the password. For more information, see Change or reset the password.
    • If you use a third-party database management tool such as RDM to connect to your ApsaraDB for Redis instance, enter user:password as the password and leave the username field empty. Otherwise, you fail to connect to the instance.
    • If password-free access is enabled for your ApsaraDB for Redis instance, you can run ApsaraDB for Redis commands without performing this step when you connect to the instance over a VPC.

    Example:

    AUTH testaccount:Rp829dlwa
    If OK is returned, you succeed to connect to the ApsaraDB for Redis instance and you can run ApsaraDB for Redis commands.

Common connection methods

Client Recommended network type Description
DMS VPC Log on to an ApsaraDB for Redis instance by using DMS
ECS instance in the same VPC as the ApsaraDB for Redis instance VPC
  • ECS instance in a different VPC from the ApsaraDB for Redis instance
  • On-premises device
Internet
Special connection methods

FAQ

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, enter 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.