redis-cli is a built-in CLI that is native to Redis. You can use redis-cli to connect to a Tair instance from an Elastic Compute Service (ECS) instance or an on-premises device to manage data.
Workflow
Step | Description |
1. Specify the account used to connect to your Tair instance and the account password. | The following methods are available:
|
2. Configure a whitelist. | The recommended network type varies based on devices. Choose a network type that suits your device and add the IP address of the device to a whitelist of the Tair instance.
For more information, see Configure a whitelist. |
3. Obtain the connection information. |
For more information, see View endpoints. |
4. Use redis-cli to connect to the Tair instance. | Run the following commands based on your needs in the directory to which redis-cli is decompressed:
For more information, see the "Procedure" section of this topic. |
Procedure
Log on to the ECS instance. Then, download and install redis-cli.
Run the following command to install GCC:
sudo yum -y install gcc
Run the following command to download the Redis source code package:
wget https://download.redis.io/releases/redis-7.0.0.tar.gz
NoteIn this example, Redis 7.0.0 is used to demonstrate the operations. You can install other versions. For more information, visit the Redis official website.
Run the following command to decompress the Redis source code package:
tar xzf redis-7.0.0.tar.gz
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-7.0.0&&make
It generally takes 2 to 3 minutes to compile and install Redis.
Run the following command to go to the src directory and connect to the instance:
cd src
Obtain the connection information and run the following command in redis-cli to connect to the Tair instance:
./redis-cli -h hostname -p port [-c]
Table 1. Parameters
Parameter
Description
Method to obtain the parameter value
hostname
The endpoint of the Tair instance.
If you connect to the Tair instance over a VPC, obtain the VPC endpoint of the instance.
If you connect to the Tair instance over the Internet, obtain the public endpoint of the instance.
For more information, see View endpoints.
port
The port number of the Tair instance.
The default port number is 6379.
-c
Specifies whether to enable the cluster mode.
The cluster mode is available only if the Tair 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
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, enter the password. For example, if the username of the default account is
r-bp1zxszhcgatnx****
and the password isPassword21
, the command used to verify the password isAUTH Password21
.If you use a custom account, enter the password in the
user:password
format. For example, if the username of the custom account istestaccount
and the password isRp829dlwa
, the command used to verify the password isAUTH testaccount:Rp829dlwa
.
NoteIf you forget your password, reset the password. If you have not set a password, set a 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 Tair instance, specify
user:password
as the password and leave the username field empty. Otherwise, connection to the instance fails.If password-free access is enabled for your Tair instance, you can run Tair commands without performing this step when you connect to the instance over a VPC.
Example:
AUTH testaccount:Rp829dlwa
If
OK
is returned, you succeed in connecting to the Tair instance and you can run Tair commands.
Common errors and troubleshooting
If the minor version of your instance is outdated, the returned error message may be misleading. We recommend that you update your instance to the latest minor version. For more information, see Update the minor version of an instance.
Error message | Cause and solution |
| A whitelist is not configured as required. For more information, see the "Workflow" section of this topic. |
| |
| The password is invalid. Specify the correct password in a valid format. The password format varies based on the selected account.
Note If you forget your password, you can reset it. For more information, see Change or reset the password. |