redis-cli is a command-line tool that is included with Redis. You can use redis-cli to connect to and manage Tair and Redis instances from an ECS instance or an on-premises device. This topic describes how to install redis-cli, connect to an instance, and troubleshoot common connection errors.
Free trial
Alibaba Cloud offers a free trial that allows new, eligible users to try Alibaba Cloud products for a limited time. For more information, see Free Trial.
Connection workflow
Procedure | Description |
1. Set the password for the instance account. | You can choose one of the following methods:
|
2. Add IP addresses to a whitelist. | Only IP addresses in the whitelist can connect to the instance. You must determine the network type based on your device and add the corresponding IP address to the instance whitelist.
For more information about how to add IP addresses to a whitelist, see Set IP whitelists. |
3. Obtain the connection information of the instance. |
For more information, see View endpoints. |
4. Use redis-cli to connect to the instance. | In the directory where you unzipped redis-cli, run the relevant commands.
For more information, see Connect to a Redis or Tair instance in this topic. |
Install redis-cli
If redis-cli is not installed on your device, you can follow these instructions to install it.
Connect to a Redis or Tair instance
Go to the directory where redis-cli is installed.
Linux
Go to the ..\redis-7.2.0\src directory. For example, run
cd /home/redis-7.2.0/src.macOS
Go to the ../redis-cli directory. For example, run
cd /opt/homebrew/bin.Windows
Open the command-line window and go to the directory where redis-cli is located.
Run the following command to connect to the instance using redis-cli:
./redis-cli -h <hostname> -p <port> [-c]NoteTo start redis-cli in Windows PowerShell, you can run the command
.\redis-cli -h hostname -p port [-c].Table 1. Parameters
Parameter
Description
How to obtain
hostname
The endpoint of the instance.
When connecting over a VPC: Get the VPC endpoint of the instance.
When connecting over the internet: Get the public endpoint of the instance.
For more information, see View endpoints.
port
The port number of the instance.
The default port number is 6379. You can also customize the port number. For more information, see Change the endpoint or port.
-c
Enable cluster mode.
This mode is available only for cluster architecture instances when you connect using a direct connection address.
Connection examples:
Default endpoint (for endpoints of standard architecture instances or proxy endpoints of cluster architecture instances):
./redis-cli -h r-bp1zxszhcgatnx****.redis.rds.aliyuncs.com -p 6379Direct connection endpoint for cluster architecture instances:
./redis-cli -h r-bp1zxszhcgatnx****.redis.rds.aliyuncs.com -p 6379 -c
Run the following command to complete password authentication:
AUTH <password>Table 2. Parameters
Parameter
Description
password
Enter the account and password based on the account type:
Default account (usually named
defaultor with the instance ID): Enter only the password.Standard account: The password format is
user:password. For example, if the custom account istestaccountand the password isRp829dlwa, you must enter the password astestaccount:Rp829dlwa.
NoteIf you forgot your password or have not set one, reset it. For more information, see Change or reset the password.
If password-free access over a VPC is enabled for the instance, password authentication is not required when you connect to the instance over the VPC. You can run commands directly.
Example:
AUTH testaccount:Rp829dlwaA response of
OKindicates that the connection is successful and you can run commands.If an error occurs, see Common errors.
For information about the commands that the instance supports, see Command overview.
Common errors
If the minor version of your instance is outdated, the returned error messages may be different from those in the following table. You can upgrade the instance to the latest minor version. For more information, see Update the minor version and proxy version.
Error message | Cause and solution |
| The correct IP address is not added to the whitelist. You can add the correct IP address to the whitelist as described in Step 2 of the Connection workflow section. |
| |
| The password is incorrect. Use the correct password and format. The password format varies based on the account type.
Note
|