redis-cli is a command-line utility that comes with Redis. You can use redis-cli to connect to and manage Tair and Redis instances from an Elastic Compute Service (ECS) instance or on-premises device. This topic describes how to install and use redis-cli to connect to a Tair or Redis instance and how to troubleshoot common connection errors.
Free trial
Alibaba Cloud Free Trial is a program that allows eligible new users to try out Alibaba Cloud services for free for a limited time. For more information, go to the free trial page.
Workflow
Step | Description |
1. Specify the account used to connect to the instance and the account password. | The following methods are available:
|
2. Configure a whitelist. | Only IP addresses in the whitelist can connect to the instance. The recommended network type varies with device. Choose a network type that suits your device and add the IP address of the device to the whitelist of the instance.
For more information, see Configure whitelists. |
3. Obtain connection information. |
For more information, see View endpoints. |
4. Use redis-cli to connect to the instance. | Run the following commands based on your needs in the directory to which redis-cli is decompressed:
For more information, see Connect to a Redis or Tair instance. |
Install redis-cli
If you do not have redis-cli installed on your device, refer to the following instructions.
Connect to a Redis or Tair instance
Go to the directory in which redis-cli is installed.
Windows
Open the CLI and go to the directory in which redis-cli is installed.
macOS
Go to the Redis directory that is suffixed with redis-cli. Example:
cd /opt/homebrew/bin
.Linux
Go to the Redis directory that is suffixed with src. Example:
cd /home/redis-7.0.0/src
.Run the following command to use redis-cli to connect to the Redis or Tair instance:
./redis-cli -h <hostname> -p <port> [-c]
NoteIf you want to start redis-cli in Windows PowerShell, run the
.\redis-cli -h hostname -p port [-c]
command.Table 1. Parameters
Parameter
Description
Method to obtain the parameter value
hostname
The endpoint of the instance.
If you connect to the instance over a VPC, obtain the VPC endpoint of the instance.
If you connect to the instance over the Internet, obtain the public endpoint of the instance.
For more information, see View endpoints.
port
The port number of the instance.
Use the default port number 6379 or specify a custom port number. For more information, see Change the endpoint or port number of an instance.
-c
Specifies whether to enable the cluster mode.
The cluster mode is available only if the instance is a cluster instance that uses a private endpoint.
Connection examples:
The following sample command is suitable for scenarios in which 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 in which 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 whose username is
default
or the same as the instance ID, enter only the password.If you use a custom account, enter the password in the
user:password
format. For example, if the username of a custom account istestaccount
and the password isRp829dlwa
, entertestaccount:Rp829dlwa
as the password.
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 password-free access is enabled for the instance, password authentication is not required when you connect to the instance over a VPC.
Example:
AUTH testaccount:Rp829dlwa
If
OK
is displayed, the instance is connected and Redis commands can be run on the instance.For information about what to do if an error occurs, see Common errors and troubleshooting.
For information about the commands supported by Tair (Redis OSS-compatible) instances, see Command overview.
Common errors and troubleshooting
If the minor version of your instance is outdated, the returned error messages may be inconsistent with those listed in the following table. 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 second step mentioned in the Workflow section. |
| |
| The password is invalid. Specify the correct password in a valid format. The password format varies with the selected account type.
Note
|