Skip to main content

MySQL to Redis Synchronization

Overview

This topic describes how to use CloudCanal build a MySQL-to-Redis data synchronization link, including the following features:

  • Support Redis single-node, primary-standby, and sharded cluster
  • Support cache expiration time when write to Redis

Key Points

Automatically Adapt to Redis Various Deployments

Redis sharded and non-sharded clusters have different ways of writing data and query metadata.

CloudCanal automatically identifies the deployment form of Redis by obtaining Redis parameters, and adjusts the writing method to make the synchronization DataJob run normally.

Support Cache Expiration

Redis can set the cache expiration time when writing data.

When creating a CloudCanal DataJob, you can optionally set the expiration time (seconds).

After creating, DataJob will set the expiration time when writing data to Redis.

Example

Install CloudCanal

Add DataSource

  • In this example, one Redis cluster purchased by Alibaba Cloud Marketplace and a MySQL are used.

  • Log in to the CloudCanal, DataSource > Add DataSource , add 2 DataSource

  • If Redis is a cluster, you can fill in all nodes or all master nodes and separate them with commas.

    mysql_redis_sync_add_ds

Create DataJob

  • DataJob->Create DataJob

  • Advanced configuration of the target DataSource, you can set the cache invalid time (second), <=0 means not set.

  • Click Next Step.

    mysql_redis_sync_first_step

  • Select Incremental, then check Full Data option.

  • Click Next Step.

    mysql_redis_sync_second_step

  • Select tables.

  • Because the cache key in Redis is composed of the primary key of the source table, it is not recommended to select the tables without a primary key.

  • Click Next Step.

    mysql_redis_sync_third_step

  • Select columns and click Next Step.

    mysql_redis_sync_fouth_step

  • Confirm the Creating.

    mysql_redis_sync_final_step

    mysql_redis_sync_data_job_normal

Test And Verify Data

  • Create INSERT,UPDATE,DELETE work load.

    mysql_redis_sync_make_data_load

  • Stop work load.

  • Create Data Verification DataJob, and the result is correct.

    mysql_redis_sync_data_correct

FAQ

What should I do if Redis is primary and standby switched?

  • CloudCanal uses JedisCluster for writes, which automatically senses changes in primary and standby changes

What about Redis changing nodes?

  • You can manually modify the node information of the task configuration and restart the task to continue.

Summary

This topic describes how to use CloudCanal to build a MySQL to Redis data synchronization link to help you accelerate your business queries.