ApsaraDB for Redis is a database service compatible with the open-source Redis protocol and provides hybrid storage of memory and hard disks. Based on reliable hot standby architecture and scalable cluster architecture, ApsaraDB for Redis is suitable for scenarios that require flexible configuration changes, high throughput, and low latency. This topic describes how to synchronize data from a Codis cluster to an ApsaraDB for Redis instance by using Data Transmission Service (DTS).

Prerequisites

  • The available storage space of the destination ApsaraDB for Redis instance is larger than the total size of data stored in the source Codis cluster.
  • All master nodes in the source Codis cluster support the PSYNC command.

How DTS synchronizes data from a Codis cluster

A Codis cluster consists of multiple Codis-Groups. You must create a data synchronization task for each Codis-Group. DTS synchronizes each Codis-Group in a data synchronization task till the whole cluster is synchronized.

Synchronize data from a Codis cluster

Architecture of the Codis cluster

In this topic, the Codis cluster consists of two Codis-Groups. Each Codis-Group runs in a master-replica architecture. The following figure shows the architecture of the cluster.

Architecture of a Codis cluster

Precautions

  • If the bind parameter is configured in the redis.conf file of the source Redis database, set the value of this parameter to the intranet IP address of ECS to ensure that DTS can connect to the source database normally.
  • We recommend that you increase the value of the repl-backlog-size parameter in the redis.conf file. This ensures the stability of data synchronization.
  • To ensure the synchronization quality, DTS adds the following key to the source Codis cluster: DTS_REDIS_TIMESTAMP_HEARTBEAT. This key is used to record the time when data is synchronized to ApsaraDB for Redis.
  • We recommend that you do not run the FLUSHDB or FLUSHALL command in the source Codis cluster. Otherwise, data may be inconsistent between the Codis cluster and the ApsaraDB for Redis instance.
  • If the data eviction policy (maxmemory-policy) of the destination database is not set to noeviction, the data between the source and destination databases may become inconsistent. For more information about the data eviction policy, see How does ApsaraDB for Redis evict data by default?
  • The database version of the destination ApsaraDB for Redis instance can be 2.8, 4.0, and 5.0. The version of the destination database must be the same as or later than the version of the source database. If you want to synchronize data between different versions of Redis databases, make sure that the versions of the source and destination databases are compatible. You can create a pay-as-you-go ApsaraDB for Redis instance to verify database compatibility. After verification, you can release the instance or change the billing method to subscription.

Operations that can be synchronized

  • APPEND
  • BITOP, BLPOP, BRPOP, and BRPOPLPUSH
  • DECR, DECRBY, and DEL
  • EVAL, EVALSHA, EXEC, EXPIRE, and EXPIREAT
  • GEOADD and GETSET
  • HDEL, HINCRBY, HINCRBYFLOAT, HMSET, HSET, and HSETNX
  • INCR, INCRBY, and INCRBYFLOAT
  • LINSERT, LPOP, LPUSH, LPUSHX, LREM, LSET, and LTRIM
  • MOVE, MSET, MSETNX, and MULTI
  • PERSIST, PEXPIRE, PEXPIREAT, PFADD, PFMERGE, PSETEX, and PUBLISH
  • RENAME, RENAME, RESTORE, RPOP, RPOPLPUSH, RPUSH, and RPUSHX
  • SADD, SDIFFSTORE, SELECT, SET, SETBIT, SETEX, SETNX, SETRANGE, SINTERSTORE, SMOVE, SPOP, SREM, and SUNIONSTORE
  • ZADD, ZINCRBY, ZINTERSTORE, ZREM, ZREMRANGEBYLEX, ZUNIONSTORE, ZREMRANGEBYRANK, and ZREMRANGEBYSCORE
Note

Procedure

  1. Purchase a data synchronization instance. For more information, see Purchase procedure.
    Note On the buy page, set Source Instance to Redis, Target Instance to Redis, and Synchronization Topology to One-Way Synchronization.
  2. Log on to the DTS console.
  3. In the left-side navigation pane, click Data Synchronization.
  4. At the top of the Synchronization Tasks page, select the region where the destination instance resides.
    Select a region
  5. Find the data synchronization instance and click Configure Synchronization Channel in the Actions column.
  6. Configure the source and destination instances.
    Configure the source and destination instances
    Section Parameter Description
    N/A Synchronization Task Name DTS automatically generates a task name. We recommend that you use an informative name for easy identification. You do not need to use a unique task name.
    Source Instance Details Instance Type Select User-Created Database in ECS Instance.
    Instance Region The region of the source instance. The region is the same as the source region that you selected when you purchased the data synchronization instance. You cannot change the value of this parameter.
    ECS Instance ID Select the ID of the ECS instance where the master node of the Codis-Group resides.
    Note DTS synchronizes each Codis-Group of the Codis cluster by using a data synchronization task till the whole cluster is synchronized. In this step, enter the ECS instance ID for the master node of Codis-Group 1. When you configure the data synchronization task for Codis-Group 2, enter the ECS instance ID for the master node of Codis-Group 2. You can configure data synchronization tasks for all Codis-Groups by following the procedure described in this topic.
    Database Type The value of this parameter is set to Redis.
    Instance Mode Select Standalone.
    Note You must select Standalone for this parameter because data from a Codis cluster cannot be synchronized at a time. DTS synchronizes each Codis-Group of the cluster in a data synchronization task till all Codis-Groups are synchronized.
    Port Number Enter the service port number of the master node in the Codis-Group.
    Database Password The database password for the master node.
    Note This parameter is optional and can be left blank if no database password is set.
    Destination Instance Details Instance Type Select Redis Instance.
    Instance Region The region of the destination instance. The region is the same as the destination region that you selected when you purchased the data synchronization instance. You cannot change the value of this parameter.
    Instance ID Select the ID of the destination ApsaraDB for Redis instance.
    Database Password Enter the database password of the destination ApsaraDB for Redis instance.
    Note
  7. In the lower-right corner of the page, click Set Whitelist and Next.
    Note The CIDR blocks of DTS servers are automatically added to the inbound rule of the ECS instance and the whitelist of the ApsaraDB for Redis instance. This ensures that DTS servers can connect to the source and destination instances.
  8. Configure the processing mode in existing destination tables and the objects to be synchronized.
    Parameter Description
    Processing Mode In Existed Target Table DTS synchronizes each Codis-Group of the Codis cluster in a data synchronization task till the whole cluster is synchronized. When you configure data synchronization for Codis-Group 1, if the ApsaraDB for Redis instance has no data, select Pre-check and Intercept. When you configure data synchronization for Codis-Groups 2 to N, select Ignore. Otherwise, errors may occur during data synchronization.
    Note
    • Pre-check and Intercept: checks whether the destination database is empty. If the destination database is empty, the precheck is passed. If the database is not empty, an error is returned during precheck and the data synchronization task cannot be started.
    • Ignore: skips the precheck for empty destination databases and continues with data synchronization. If the keys in the destination database are the same as those in the source database during data synchronization, the keys in the source database overwrite those in the destination database.
    Objects to be synchronized
    • Select databases from the Available section and click the icon to move the databases to the Selected section.
    • You can select only databases as the objects to be synchronized. You cannot select keys as the objects to be synchronized.
  9. In the lower-right corner of the page, click Next.
  10. Configure initial synchronization.
    Configure initial synchronization for Redis databases
    Note The value is set to Include full data + incremental data. DTS synchronizes historical data from the source Codis cluster to the destination Redis database before synchronizing incremental data.
  11. In the lower-right corner of the page, click Precheck.
    Note
    • Before you can start the data synchronization task, a precheck is performed. You can start the data synchronization task only after the task passes the precheck.
    • If the task fails to pass the precheck, click the Info icon icon next to each failed item to view details. Troubleshoot the issues based on the causes and run the precheck again.
  12. Close the Precheck dialog box after the following message is displayed: The precheck is passed.
  13. Wait until the initial synchronization is complete and the data synchronization task is in the Synchronizing state.
    Synchronizing
    Note You can view the status of the data synchronization task on the Synchronization Tasks page.
  14. Create and configure a data synchronization task for the other Codis-Group by following steps 1 to 13.

Result

In this topic, the Codis cluster consists of two Codis-Groups. You must create two data synchronization tasks. The following figure shows that the initial synchronization is complete for both tasks and both tasks are in the Synchronizing state.

Synchronization tasks configured for the Codis cluster

In this topic, the databases DB0 and DB1 are synchronized. You can use Data Management (DMS) to log on to the ApsaraDB for Redis instance and check the total number of keys in the ApsaraDB for Redis instance. The total number of keys is the same as that in the source Codis cluster.

Figure 1. ApsaraDB for Redis instance
Figure 2. Source Codis cluster