redis-shake is an open source tool developed by Alibaba Cloud to transmit data of Redis databases. This tool provides the sync mode that allows you to synchronize data from one ApsaraDB for Redis instance to another in real time.

Prerequisites

  • An ApsaraDB for Redis instance is created as the destination instance.
  • An Elastic Compute Service (ECS) instance based on the 64-bit Linux operating system is created to run redis-shake.
  • The ECS instance can access the destination ApsaraDB for Redis instance.

Background

The redis-shake tool can be used to parse (decode mode), recover (restore mode), back up (dump mode), and synchronize (sync/rump mode) data in Redis databases. In sync mode, the redis-shake tool runs a SYNC or PSYNC command to synchronize full or incremental data from the source Redis database to the destination Redis database. Incremental synchronization automatically starts after full synchronization is completed. The sync mode applies to scenarios such as data migration from a user-created Redis database to the cloud, data synchronization between a user-created Redis database and an ApsaraDB for Redis instance, and data synchronization between user-created Redis databases.

Note
  • In sync mode, the source Redis database must support the SYNC and PSYNC commands. If you use the sync mode of the redis-shake tool to synchronize data from ApsaraDB for Redis, you must use a database account that has the Replicate permission to connect to the source ApsaraDB for Redis instance.
  • The sync mode supports data synchronization between different database versions, such as between Redis 2.8 and Redis 4.0.
  • Currently, ApsaraDB for Redis cluster instances cannot act as the source of data migration in sync mode.
  • For more information about the redis-shake tool, see redis-shake on GitHub or FAQ.

Procedure

  1. Log on to the ECS instance that can access the destination ApsaraDB for Redis instance.
  2. Download the redis-shake tool in the ECS instance.
    Note We recommend that you download the latest version.
  3. Run the following command to decompress the downloaded redis-shake.tar.gz package:
    # tar -xvf redis-shake.tar.gz
    Note In the decompressed folder, the redis-shake file is a binary file that can be run in the 64-bit Linux operating system. The redis-shake.conf file is the configuration file of the redis-shake tool. You need to modify this configuration file in the next step.
  4. Modify the redis-shake.conf file. The following table describes the parameters for the sync mode of the redis-shake tool.
    Table 1. Parameters for the sync mode of the redis-shake tool
    Parameter Description Example
    source.address The connection address and service port of the source Redis database. xxx.xxx.1.10:6379
    source.password_raw The password of the source Redis database. SourcePass233
    Note If you synchronize data from ApsaraDB for Redis, you must use a database account that has the Replicate permission to connect to the source ApsaraDB for Redis instance. In this case, set this parameter in the following format: account:password.
    target.address The connection address and service port of the destination ApsaraDB for Redis instance. r-bp1xxxxxxxxxxxxx.redis.rds.aliyuncs.com:6379
    target.password_raw The password of the destination ApsaraDB for Redis instance. TargetPass233
    rewrite Specifies whether to overwrite the existing keys in the ApsaraDB for Redis instance that are identical to those in the RDB file. Valid values:
    • true
    • false
    Note The default value is true. We recommend that you back up the valid data of the destination ApsaraDB for Redis instance before data migration. If you set this parameter to false and a key exists in both the source and destination databases, an error message is returned.
    true
    target.db

    The database to which data is synchronized in the destination ApsaraDB for Redis instance.

    For example, to synchronize data to database 10 of the destination ApsaraDB for Redis instance, set this parameter to 10.

    If you set this parameter to -1, data is synchronized to the database that has the same name as the source database. For example, the data of database 0 on the source ApsaraDB for Redis instance is synchronized to database 0 on the destination ApsaraDB for Redis instance, and the data of database 1 on the source ApsaraDB for Redis instance is synchronized to database 1 on the destination ApsaraDB for Redis instance.

    0
    parallel The number of concurrent threads used to synchronize the RDB file. A larger number of concurrent threads indicates higher synchronization performance.
    Note
    • The minimum value is 1.
    • The maximum value depends on the server performance.
    • We recommend that you set the parameter to 64.
    64
  5. Run the following command to start synchronization:
    # ./redis-shake -type=sync -conf=redis-shake.conf
    Note You must run this command in the directory that contains the redis-shake and redis-shake.conf files. Otherwise, you must specify the file path that contains the two files in the command.
  6. Check the synchronization status in the synchronization log. When sync rdb done appears in the log, full synchronization is completed and incremental synchronization starts.
    Figure 1. Synchronization logs
    Example of using the redis-shake tool to migrate data of a Redis database