首页 Data Transmission Service Support Troubleshooting Data inconsistency after Redis synchronization

Data inconsistency after Redis synchronization

更新时间: 2026-06-03 20:20:27

This topic describes how to identify and troubleshoot data inconsistency after Redis synchronization.

Problem description

After you use Data Transmission Service (DTS) to synchronize Redis, data is inconsistent between the source and destination.

Example

After you use Data Transmission Service (DTS) to synchronize Redis data, you run theinfo keyspace command to check the keys on the source and destination. The output shows that the data is inconsistent, with a large proportion of keys having an expiration time.

xxx> info keyspace
# Keyspace
db0:keys=769509,expires=227386,avg_ttl=3426607441
db3:keys=254,expires=0,avg_ttl=0
db2:keys=17,expires=2,avg_ttl=837582
db1:keys=2,expires=0,avg_ttl=0
db15:keys=2,expires=0,avg_ttl=0
[work@rec01 bin]$ ./redis-cli -a 'xxx'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info keyspace
# Keyspace
db0:keys=772864,expires=230736,avg_ttl=3380950183
db1:keys=2,expires=0,avg_ttl=0
db2:keys=17,expires=2,avg_ttl=868931
db3:keys=254,expires=0,avg_ttl=0
db15:keys=2,expires=0,avg_ttl=0
127.0.0.1:6379>

Cause

Relying solely on theinfo keyspace command'sexpires value to verify data consistency is misleading because the command provides estimates, not exact values.

  • In the output of theinfo keyspace command:

    • keys indicates the total number of keys.

    • expires indicates the number of keys that have an expiration time, including both unexpired and expired keys.

Therefore, when you use theexpires value to check for consistency, keys that have logically expired but have not yet been actively deleted by Redis are included in the count. This leads to the apparent data inconsistency between the source and destination.

Note

Redis removes expired keys under the following conditions:

  • Redis periodically clears expired keys when the CPU is idle.

  • When a key is accessed, Redis checks if it has expired and evicts it if so.

  • During a SCAN operation, Redis checks for and evicts any expired keys it encounters.

For more information about the eviction policy for expired keys in Redis, see How Redis Handles Expired Keys.

Solution

To verify data consistency, use one of the following methods:

Note

When checking for data loss after synchronization, do not rely solely on theexpires statistic, as it includes data that has already expired and makes theexpires value an unreliable measure of consistency.

  1. For both the source and destination databases, use the keys count and subtract the expires count to find the number of permanent keys. If the difference between the results for each database is negligible, the data can be considered consistent.

  2. Use the redis-full-check tool for verification. For more information, see Use the redis-full-check tool.

Note

How can you make the key counts in theinfo keyspace output appear consistent?

We recommend clearing expired Redis data. The methods for cloud databases and self-managed databases are as follows:

  • Tair (Redis OSS-Compatible): Log on to the Tair (Redis OSS-Compatible) console and use the Clear Data feature. For ApsaraDB for Redis, open the Clear Data dialog box in the console, select the Expired Data tab, choose an execution time (Immediately or Within Maintenance Window), and then click OK. This action runs a SCAN command to bulk-delete all expired data from the instance. This operation is irreversible, and the deleted data cannot be recovered.

  • self-managed Redis database: Use the redis-full-check tool to run a verification. The tool executes commands like SCAN, triggering the cleanup of expired data during the process.

上一篇: What can I do if data loss occurs in the destination database due to online DDL operations performed in a table merging task? 下一篇: What can I do if data loss occurs after I perform two-way synchronization among three instances?
阿里云首页 数据传输服务 相关技术圈