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 Twemproxy Redis cluster to an ApsaraDB for Redis instance by using Data Transmission Service (DTS).
Prerequisites
- An ApsaraDB for Redis instance is created. For more information, see Create an ApsaraDB for Redis instance.
- The available storage space of the ApsaraDB for Redis instance is larger than the total size of data stored in the Twemproxy Redis cluster.
- All master nodes in the Twemproxy Redis cluster support the
PSYNC
command.
How DTS synchronizes data from a Twemproxy Redis cluster
A Twemproxy Redis cluster consists of multiple Redis-Servers. DTS synchronizes data of each Redis-Server in a data synchronization task until the whole cluster is synchronized.

Architecture of the Twemproxy Redis cluster
In this topic, the Twemproxy Redis cluster consists of two Redis-Servers. Each Redis-Server runs in a master-replica architecture. The following figure shows the architecture of the cluster.

Precautions
- DTS uses the resources of the source and destination instances during initial full data synchronization. This may increase the loads of the database servers. If you synchronize a large amount of data or the server specifications cannot meet your requirements, database services may become unavailable. Before you synchronize data, evaluate the impact of data synchronization on the performance of the source and destination databases. We recommend that you synchronize data during off-peak hours.
- If the
bind
parameter is configured in the redis.conf file of the source database, you must set the value of this parameter to the internal IP address of the ECS instance. The setting ensures that DTS can connect to the source database. - To ensure the stability of data synchronization, we recommend that you increase the
value of the repl-backlog-size parameter in the
redis.conf
file of the source Codis cluster. - 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
orFLUSHALL
command in the source Codis cluster. Otherwise, data may become inconsistent between the Codis cluster and the ApsaraDB for Redis instance. - If the data eviction policy (
maxmemory-policy
) of the destination instance is not set tonoeviction
, data between the source and destination instances may become inconsistent. For more information about the data eviction policy, see How does ApsaraDB for Redis evict data by default? - If an expiration policy is enabled for some keys in the source database, these keys
may not be deleted in a timely manner after they expired. Therefore, the number of
keys in the destination database may be less than that in the source database. You
can run the info command to view the number of keys in the destination database.
Note The number of keys that do not have an expiration policy or have not expired is the same in the source and destination databases.
- The database version of the destination ApsaraDB for Redis instance must be 2.8, 4.0, or 5.0. The version of the destination database must be the same as or later than the version of the source database. If you synchronize data between different versions of Redis databases, make sure that the versions of the source and destination databases are compatible with each other. You can create a pay-as-you-go ApsaraDB for Redis instance to verify database compatibility. After the 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, RENAMENX, 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
- If you run the EVAL or EVALSHA command to execute Lua scripts, DTS cannot identify whether the Lua scripts are executed in the destination database. During incremental data synchronization, the destination database does not return the execution results of Lua scripts.
- When DTS runs the SYNC or PSYNC command to synchronize data of the LIST type, DTS does not clear the existing data. In this case, the destination database may contain duplicate data.
Procedure
Result
In this topic, the Twemproxy Redis cluster consists of two Redis-Servers. 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.

In this topic, the database DB0 is synchronized. You can use Data Management (DMS) to log on to the destination 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 Twemproxy Redis cluster.

