tencent cloud

Feedback

Connecting to TencentDB for Redis Instance

Last updated: 2023-03-14 15:51:56

    Overview

    This document describes three methods for connecting to a running instance. Then, you can run Redis commands for read, write, and query.
    Connection via client: You can connect to a TencentDB instance at its automatically assigned private address from a Windows or Linux CVM instance. This connection method utilizes the high-speed private network of Tencent Cloud and features low delay. Both instances should be under the same account and reside in the same VPC in the same region or reside in the classic network.
    Notes
    CVM and TencentDB instances in different VPCs (under the same or different accounts in the same or different regions) can be interconnected over the private network through Cloud Connect Network.
    CVM and TencentDB instances in different VPCs can be connected through the public network address as instructed in Configuring Public Network Address.
    Connection via DMC: You can use Tencent Cloud Database Management Center (DMC) to log in to your TencentDB instance to access them, view their key metric information, and run Redis commands.
    Connection via SDK: You can connect to a TencentDB for Redis instance by configuring its private IP, port, instance ID, and password in the SDK for the corresponding programming language. Then, you can manipulate it, get and set its key, and do more.

    Preparations

    Prepare a TencentDB for Redis instance. For more information, see Creating TencentDB for Redis Instance.
    Prepare a database account and password. For more information, see Managing Account. You can use the default account or a custom account.
    Configure security group rules for the CVM instance and the TencentDB for Redis instance. For more information, see Configuring Security Group.
    Obtain the Private IPv4 Address for database connection in the Network Info section on the Instance Details page in the TencentDB for Redis console.

    Connecting Using a Client Tool

    Notes:
    Currently, Redis 6.2 does not support the RESP3 protocol.

    Connecting from a Linux CVM instance

    Step 1. Prepare the environment

    1. Log in to the Linux CVM instance. For more information, see Customizing Linux CVM Configurations.
    2. Taking a CVM instance on CentOS as an example, run the following command to install the Redis client.
    yum install redis -y
    If Complete! is displayed, the client is installed successfully.

    Step 2. Connect to an instance

    Passwordless authentication If your instance is password-free, the connection command is as follows:
    redis-cli -h IP address -p port
    Here, the IP address and port are the Private IPv4 Address and Port obtained in the Network Info section on the Instance Details page in the TencentDB for Redis console.
    
    Access with default account
    The default account refers to the account assigned by the system by default. When you purchase and create a TencentDB for Redis instance, the password you set to access the instance is the database password corresponding to the default account. To use the default account with a password to access the database, the following open-source connection command is supported:
    redis-cli -h IP address -p port -a password
    Here, the IP address and port are the Private IPv4 Address and Port obtained in the Network Info section on the Instance Details page in the TencentDB for Redis console. For example, if the password you set is abcd1234, the connection command should be as follows:
    redis-cli -h IP address -p port -a abcd1234
    Notes
    To access instances purchased before January 2018, you need to replace the "password" with "instance ID:password", for example, redis-cli -h IP address -p port -a crs-bkuza6i3:abcd1234.
    Access with custom account If you use a custom account as described in Managing Account when connecting, then the authentication method of the custom account is account name@password, which acts as the password parameter for accessing TencentDB for Redis:
    redis-cli -h IP address -p port -a account name@password

    Connecting from a Windows CVM instance

    1. Configure and log in to the Windows CVM instance. For more information, see Customizing Windows CVM Configurations.
    2. In the Windows CVM instance, download the TencentDB for Redis client over the internet and install it.
    3. Open the TencentDB for Redis client, configure the instance's private IP address, and click Test Connection to connect to the instance.
    Parameter
    Description
    Name
    The name of the connection to the database instance.
    Address
    Enter the private IPv4 address of the database instance, which can be obtained in the Network Info section on the Instance Details page in the console.
    Verification
    Enter the password for database instance connection.
    
    4. Click
    
    and enter a Redis command in the input box in the bottom-right corner to run it.

    Connection via DMC

    1. Log in to the TencentDB for Redis console.
    2. Above the instance list, select the region.
    3. In the instance list, find the target instance.
    4. Click Log In in the Operation column.
    5. You will be redirected to the login page of DMC. Enter the default account password of the target instance and click Log In.
    
    6. You can view the instance monitoring information on the Instance Info tab on the Database Management page.
    
    7. Click the Command Line tab and enter a Redis command in the input box at the bottom to run it:
    
    8. If you are unfamiliar with Redis command parameters, you can select the slot range and database for storing key values in the Object List section on the left of the page, click Create, select the key data type, click OK, edit the key name in the Key Name input box, and click Add element and create key. Then, enter the corresponding key value and click OK in the Add Element window. The system will run commands based on the set key and key value.
    

    Connection via SDK

    TencentDB for Redis can be accessed via SDKs for various programming languages, including PHP, Java, Node.js, Python, C, Go, and .NET. For specific samples, see PHP Connection Sample. You can download an SDK client and then connect to a TencentDB for Redis instance by configuring its private IP, port, instance ID, and password as instructed in the sample code.

    FAQs

    For FAQs, see Connection and Login.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support