edit-icon download-icon

Hybrid access of ApsaraDB for Redis

Last Updated: Aug 28, 2017

Follow the instructions to migrate the network of a Redis instance from the classic network to the Virtual Private Cloud (VPC), while retaining the connection endpoint of the classic network.

Note: During the migration, you can specify the reservation time of the classic network endpoint. Once the reservation time is expired, the classic network endpoint will be released automatically. You will receive a notification before releasing.

Before you begin

Before migrating to VPC, check the following:

  • Verify whether the current network type is classic network.

  • Verify whether there are available VPC and VSwitch under the zone of the Redis instance. If not, see Create VPC and Create VSwitch to create one.

Migrate to VPC using the Redis console

  1. Log on to the Redis console.

  2. Click the ID of the target instance.

  3. On the Instance Information page, click Switch to VPC Network.

  4. In the displayed dialog box, complete the following configurations and then click OK.

    1. Select a VPC and a VSwitch where the Redis instance is migrated.

    2. Select Yes for the Retain the connection address of the classic network option.

      When the reservation time is expired, the classic network endpoint will be released automatically. A notification will send to you before releasing.

      Switch to VPC

  5. When the migration is completed, click Refresh.

    Both the VPC and classic endpoints are displayed.

    Redis connection endpoint

Migrate to VPC using API

  1. Download the SDK.

  2. Call the SwitchNetwork API to migrate to VPC.

    Request parameters

    Request parametersData typeRequired or notDescription
    ActionStringYes

    System parameter.

    Valid value: SwitchNetwork

    InstanceIdStringYesID of the target Redis instance.
    TargetNetworkTypeStringYes

    Specify the network type, enter VPC in this tutorial. Valid values are:

    VPC: Virtual Private Cloud

    Classic: classic network

    VPCIdStringNoID of the VPC
    VSwitchIdStringNo

    ID of the VPC.

    Required if the specified network type is VPC.

    RetainClassicStringNo

    Choose whether to reserve the classic network endpoint for the Redis instance. The default value is False. Set to True to reserve the classic network endpoint.

    ClassicExpiredDaysStringNo

    A period of time that the classic network endpoint is reserved.

    Valid values: 1 to 180 days.

    Required if choosing to reserve the classic network endpoint.

    Response parameters

    Response parametersData typeDescription
    RequestIdStringThe unique ID of the request.
    TaskIdStringTask ID.

    Example

    1. import com.aliyuncs.DefaultAcsClient;
    2. import com.aliyuncs.IAcsClient;
    3. import com.aliyuncs.exceptions.ClientException;
    4. import com.aliyuncs.exceptions.ServerException;
    5. import com.aliyuncs.profile.DefaultProfile;
    6. import com.aliyuncs.profile.IClientProfile;
    7. import com.aliyuncs.r_kvstore.model.v20150101.SwitchNetworkRequest;
    8. import com.aliyuncs.r_kvstore.model.v20150101.SwitchNetworkResponse;
    9. import org.junit.Test;
    10. /**
    11. * Created by wb259286 on 2017/6/9.
    12. */
    13. public class SwitchNetworkTest {
    14. @Test
    15. public void switchNetwork_success() {
    16. SwitchNetworkRequest request=new SwitchNetworkRequest();
    17. request.setInstanceId("ID of the target instance");
    18. request.setTargetNetworkType("VPC");
    19. request.setVpcId("VPC ID");
    20. request.setVSwitchId("VSwitch ID");
    21. request.setRetainClassic("True to reserve, False not");
    22. request.setClassicExpiredDays("Reservation time");
    23. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "AccessKey");
    24. IAcsClient client = new DefaultAcsClient(profile);
    25. try {
    26. SwitchNetworkResponse response
    27. = client.getAcsResponse(request);
    28. System.out.println(response.getRequestId());
    29. }catch (ServerException e) {
    30. e.printStackTrace();
    31. }
    32. catch (ClientException e) {
    33. e.printStackTrace();
    34. }
    35. }
    36. }
  3. Call the DescribeDBInstanceNetInfo API to obtain the classic network endpoint.

    Request parameters

    Request parametersData typeRequired or notDescription
    ActionStringYes

    System parameter.

    Valid value: DescribeDBInstanceNetInfo

    InstanceIdStringYesID of the target Redis instance.

    Response parameters

    Response parametersData typeDescription
    NetInfoItemsListThe connection information of the Redis instance.
    InstanceNetworkTypeString

    The network type of the Redis instance.

    VPC: Virtual Private Cloud

    Classic: classic network

    Data structure of the DBInstanceNetInfo parameter

    ParametersData typeDescription
    ConnectionStringStringDNS connection endpoint.
    IPAddressStringIP address.
    IPTypeStringNetwork type: Private and Public.
    PortStringPort number.
    VPCIdStringVPC ID.
    VSwitchIdStringVSwitch ID.
    ExpiredTimeStringExpiration date.

    Error code

    Error codeStatus codeDescription
    Forbidden.InstanceNotFound404The specified instance is not found.

    Example

    1. import com.aliyuncs.DefaultAcsClient;
    2. import com.aliyuncs.IAcsClient;
    3. import com.aliyuncs.exceptions.ClientException;
    4. import com.aliyuncs.exceptions.ServerException;
    5. import com.aliyuncs.profile.DefaultProfile;
    6. import com.aliyuncs.profile.IClientProfile;
    7. import com.aliyuncs.r_kvstore.model.v20150101.DescribeDBInstanceNetInfoRequest;
    8. import com.aliyuncs.r_kvstore.model.v20150101.DescribeDBInstanceNetInfoResponse;
    9. import org.junit.Test;
    10. /**
    11. *
    12. */
    13. public class DescribeDBInstanceNetInfoTest {
    14. @Test
    15. public void describeDBInstanceNetInfo_success() {
    16. DescribeDBInstanceNetInfoRequest request=new DescribeDBInstanceNetInfoRequest();
    17. request.setInstanceId("");
    18. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "YourAccesskey");
    19. IAcsClient client = new DefaultAcsClient(profile);
    20. try {
    21. DescribeDBInstanceNetInfoResponse response
    22. = client.getAcsResponse(request);
    23. System.out.println(response.getRequestId());
    24. }catch (ServerException e) {
    25. e.printStackTrace();
    26. }
    27. catch (ClientException e) {
    28. e.printStackTrace();
    29. }
    30. }
    31. }
Thank you! We've received your feedback.