diff --git a/core/riot-core/src/main/java/com/redis/riot/core/processor/IgnoreKeysWithTTLProcessor.java b/core/riot-core/src/main/java/com/redis/riot/core/processor/IgnoreKeysWithTTLProcessor.java new file mode 100644 index 000000000..a167d72eb --- /dev/null +++ b/core/riot-core/src/main/java/com/redis/riot/core/processor/IgnoreKeysWithTTLProcessor.java @@ -0,0 +1,14 @@ +package com.redis.riot.core.processor; + +import com.redis.spring.batch.common.KeyValue; +import org.springframework.batch.item.ItemProcessor; + +public class IgnoreKeysWithTTLProcessor implements ItemProcessor, KeyValue> { + @Override + public KeyValue process( KeyValue item) throws Exception { + if ( item.getTtl() > 0L ) { + return null; + } + return item; + } +} diff --git a/plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java b/plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java index 06ee4d07b..1b85150fe 100644 --- a/plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java +++ b/plugins/riot/src/main/java/com/redis/riot/cli/Replicate.java @@ -7,6 +7,7 @@ import java.util.concurrent.BlockingQueue; import java.util.logging.Logger; +import com.redis.riot.core.processor.IgnoreKeysWithTTLProcessor; import org.springframework.batch.core.Job; import org.springframework.batch.core.job.builder.FlowBuilder; import org.springframework.batch.core.job.builder.JobFlowBuilder; @@ -167,7 +168,8 @@ private Job liveJob(ReplicateCommandContext context) { private boolean shouldCompare() { return !replicateOptions.isNoVerify() && !writerOptions.isDryRun() - && !replicateOptions.getKeyProcessor().isPresent(); + && !replicateOptions.getKeyProcessor().isPresent() + && !replicateOptions.isIgnoreKeysWithTtl(); } private SimpleStepBuilder, KeyValue> scanStep(ReplicateCommandContext context) { @@ -263,6 +265,9 @@ private ItemProcessor, KeyValue> processor(ReplicateCom Expression expression = parser.parseExpression(p); processors.add(new KeyValueProcessor(expression, evaluationContext)); }); + if (replicateOptions.isIgnoreKeysWithTtl()) { + processors.add(new IgnoreKeysWithTTLProcessor()); + } return CompositeItemStreamItemProcessor.delegates(processors.toArray(new ItemProcessor[0])); } diff --git a/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java b/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java index fae3f16c2..127e14119 100644 --- a/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java +++ b/plugins/riot/src/main/java/com/redis/riot/cli/common/ReplicateOptions.java @@ -36,6 +36,9 @@ public class ReplicateOptions { @Option(names = "--ttl-tolerance", description = "Max TTL difference to use for dataset verification (default: ${DEFAULT-VALUE}).", paramLabel = "") private long ttlTolerance = KeyComparisonItemReader.DEFAULT_TTL_TOLERANCE.toMillis(); + @Option(names = "--ignore-ttl-keys", description = "Ignore keys with TTL (default: false)", paramLabel = "") + private boolean ignoreKeysWithTtl = false; + @Option(names = "--show-diffs", description = "Print details of key mismatches during dataset verification. Disables progress reporting.") private boolean showDiffs; @@ -151,6 +154,15 @@ public void setShowDiffs(boolean showDiffs) { this.showDiffs = showDiffs; } + + public boolean isIgnoreKeysWithTtl() { + return ignoreKeysWithTtl; + } + + public void setIgnoreKeysWithTtl(boolean ignoreKeysWithTtl) { + this.ignoreKeysWithTtl = ignoreKeysWithTtl; + } + public PoolOptions targetPoolOptions() { return PoolOptions.builder().maxTotal(targetPoolMaxTotal).build(); }