This topic describes how to switch the network type of an ApsaraDB for Redis (Redis) instance from classic network to virtual private cloud (VPC) by using the console or by calling the relevant API operation. When you switch the network type, you can specify a retention period for the classic network endpoint. After the retention period expires, the classic network endpoint is automatically deleted.

Prerequisites

Before you switch the network type, make sure that the following requirements are met:
  • An Alibaba Cloud account is created. If you do not have an Alibaba Cloud account, create one. For more information, see Create an Alibaba Cloud account.
  • The Redis instance is deployed in a classic network.
  • VPCs and vSwitches are available in the zone to which the Redis instance belongs. For more information, see Work with VPCs.

Switch the network type in the console

  1. Log on to the ApsaraDB for Redis console.
  2. Select the region where the Redis instance is deployed.
  3. Click the ID of the Redis instance.
  4. On the Instance Information page, click Switch to VPC.
  5. In the Switch to VPC dialog box, perform the following operations:
    1. Select the VPC and vSwitch that you want to manage.
    2. You can choose to retain a classic network endpoint and specify a retention period.
      Note After you select to retain the classic network endpoint, the classic network endpoint and the VPC endpoint remain two different endpoints. ECS instances in the classic network can still access the database and services are not affected. When the classic network endpoint expires, it is automatically deleted and you cannot access the database through the classic network endpoint.
    3. Click OK.
  6. You can click Refresh on the Instance Information page to view the endpoints of the classic network and VPC.
    Instance information

Modify the retention period of the classic network endpoint in the console

After you set the retention period for the classic network endpoint, you can change the expiration date in the console to extend the retention period before the endpoint expires.

During the period in which your instance can be connected over the classic network or VPC, you can specify the expiration date for the classic network endpoint. The changes immediately take effect. For example, if the classic network endpoint is about to expire on August 18, 2017 and you extend the expiration date by 14 days on August 15, 2017, the classic network endpoint is released on August 29, 2017.

  1. Log on to the ApsaraDB for Redis console.
  2. Select the region where the Redis instance is deployed.
  3. Click the ID of the Redis instance.
  4. In the Retained Classic Network IP Address section, click Change Expiration Date.
  5. In the Change Expiration Date dialog box, select a new expiration time and click OK.

Switch the network type by calling the relevant API operation

  1. Download relevant SDKs.The SDK of ApsaraDB for Memcache is the same as that of ApsaraDB for Redis.
  2. Call the SwitchNetwork operation to switch the network type.
    Request parameters
    Parameter Type Required Description
    Action String Yes The operation that you want to perform. Set the value to SwitchNetwork.
    InstanceId String Yes The ID of the Redis instance.
    TargetNetworkType String Yes The network type of the instance. Valid values:
    • VPC: a VPC
    • Classic: a classic network
    VPCId String No The ID of the VPC.
    VSwitchId String No

    The ID of the vSwitch.

    This parameter is required if the VPC ID is set.

    RetainClassic String No Specifies whether to retain the classic network endpoint. Default: False.
    • True: retains the classic network endpoint.
    • False: does not retain the classic network endpoint.
    ClassicExpiredDays String No

    The retention period of the classic network endpoint. Unit: days. Valid values: 1 to 120. Default value: 7.

    This parameter is required if RetainClassic is set to True.

    Response parameters
    Parameter Type Description
    RequestId String The ID of the request.
    TaskId String The ID of the task.
    Example
    import com.aliyuncs.DefaultAcsClient;
     import com.aliyuncs.IAcsClient;
     import com.aliyuncs.exceptions.ClientException;
     import com.aliyuncs.exceptions.ServerException;
     import com.aliyuncs.profile.DefaultProfile;
     import com.aliyuncs.profile.IClientProfile;
     import com.aliyuncs.r_kvstore.model.v20150101.SwitchNetworkRequest;
     import com.aliyuncs.r_kvstore.model.v20150101.SwitchNetworkResponse;
     import org.junit.Test;
     /**
      * Created by wb259286 on 2017/06/09.
      */
     public class SwitchNetworkTest {
         @Test
         public  void switchNetwork_success() {
             SwitchNetworkRequest request=new SwitchNetworkRequest();
             request.setInstanceId("<Your instance ID>");
             request.setTargetNetworkType("VPC");
             request.setVpcId("<VpcId: This parameter is required if TargetNetworkType is set to VPC.>");
             request.setVSwitchId("<VSwitchId: This parameter is required if TargetNetworkType is set to VPC>");
             request.setRetainClassic("<Specifies whether to retain the classic network endpoint. The value True specifies to retain the classic network endpoint, while the value False does not.>");
             request.setClassicExpiredDays("The retention period of the classic network endpoint");
             IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<Your AccessKey ID>",
                 "<Your AccessKey secret>");
             IAcsClient client = new DefaultAcsClient(profile);
             try {
                 SwitchNetworkResponse response
                     = client.getAcsResponse(request);
                 System.out.println(response.getRequestId());
         }catch (ServerException e) {
                 e.printStackTrace();
         }
             catch (ClientException e) {
                 e.printStackTrace();
             }
         }
     }
  3. Call the DescribeDBInstanceNetInfo operation to view the classic network endpoint and the VPC endpoint.
    Request parameters
    Parameter Type Required Description
    Action String Yes The operation that you want to perform. Set the value to DescribeDBInstanceNetInfo.
    InstanceId String Yes The ID of the Redis instance.
    Response parameters
    Parameter Type Description
    NetInfoItems List The connection information about the Redis instance.
    InstanceNetworkType String The network type of the Redis instance. Valid values:
    • VPC: a VPC
    • Classic: a classic network
    InstanceNetInfo
    Parameter Type Description
    ConnectionString String The DNS connection string.
    IPAddress String The IP address.
    IPType String
    The type of IP address for the Redis instance deployed in a classic network. Valid values:
    • Inner: a private IP address
    • Public: a public IP address
    The type of IP address for the Redis instance deployed in a VPC. Valid values:
    • Private : a private IP address
    • Public: a public IP address
    Port String The port information.
    VPCId String The ID of the VPC.
    VSwitchId String The ID of the vSwitch.
    ExpiredTime String The expiration date.
    Example
    import com.aliyuncs.DefaultAcsClient;
     import com.aliyuncs.IAcsClient;
     import com.aliyuncs.exceptions.ClientException;
     import com.aliyuncs.exceptions.ServerException;
     import com.aliyuncs.profile.DefaultProfile;
     import com.aliyuncs.profile.IClientProfile;
     import com.aliyuncs.r_kvstore.model.v20150101.DescribeDBInstanceNetInfoRequest;
     import com.aliyuncs.r_kvstore.model.v20150101.DescribeDBInstanceNetInfoResponse;
     import org.junit.Test;
     /**
      *
      */
     public class DescribeDBInstanceNetInfoTest {
     @Test
         public  void describeDBInstanceNetInfo_success() {
             DescribeDBInstanceNetInfoRequest request=new     DescribeDBInstanceNetInfoRequest();
             request.setInstanceId("<Your instance ID>");
             IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<Your AccessKey ID>",
                 "<Your AccessKey secret>");
             IAcsClient client = new DefaultAcsClient(profile);
             try {
                 DescribeDBInstanceNetInfoResponse response
                     = client.getAcsResponse(request);
                 System.out.println(response.getRequestId());
         }catch (ServerException e) {
                 e.printStackTrace();
             }
             catch (ClientException e) {
             e.printStackTrace();
             }
         }
     }

Modify the retention period of the classic network endpoint by using the relevant API operation

  1. Download relevant SDKs.The SDK of ApsaraDB for Memcache is the same as that of ApsaraDB for Redis.
  2. Call the ModifyInstanceNetExpireTime API operation to switch the network type.
    Request parameters
    Parameter Type Required Description
    Action String Yes The operation that you want to perform. Set the value to ModifyInstanceNetExpireTime.
    InstanceId String Yes The ID of the Redis instance.
    ConnectionString String Yes The endpoint of the classic network.
    ClassicExpiredDays Integer Yes

    Specifies the retention period.

    Valid values: 14, 30, 60, and 120.

    Response parameters
    Parameter Type Description
    RequestId String The ID of the request.
    Example
    public static void main(String[] args) {
         ModifyInstanceNetExpireTimeRequest request = new ModifyInstanceNetExpireTimeRequest();
         request.setClassicExpiredDays(3);
         request.setConnectionString("<The connection string>");
         request.setInstanceId("<Your instance ID>");
         IClientProfile profile
                 = DefaultProfile.getProfile("cn-hangzhou", "<Your AccessKey ID>",
                 "<Your AccessKey secret>");
         IAcsClient client = new DefaultAcsClient(profile);
         try {
             ModifyInstanceNetExpireTimeResponse response
                     = client.getAcsResponse(request);
             for (NetInfoItem item:response.getNetInfoItems()) {
                 System.out.println(item.getConnectionString());
                 System.out.println(item.getPort());
                 System.out.println(item.getDBInstanceNetType());
                 System.out.println(item.getIPAddress());
                 System.out.println(item.getExpiredTime());
             }
         }catch (ServerException e) {
             e.printStackTrace();
         }
         catch (ClientException e) {
             e.printStackTrace();
         }
     }