Skip to content

Commit c40abe0

Browse files
authored
Merge pull request #61 from raghu-nandan-bs/ignore-keys-with-ttl
add flag to ignore keys that have ttl
2 parents 0780f00 + 67aa707 commit c40abe0

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/main/java/com/moilioncircle/redis/rdb/cli/cmd/XRmt.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,18 @@ private static class RmtExclusive {
109109

110110
@Option(names = {"-l", "--legacy"}, description = {"If specify the <replace> and this parameter.", "then use lua script to migrate data to target.", "if target redis version is greater than 3.0.", "no need to add this parameter."})
111111
private boolean legacy;
112-
112+
113+
@Option(names = {"-x", "--ignore-keys-with-ttl"}, description = {"Ignore keys whose TTL is set", "default is false."})
114+
private boolean ignoreKeysWithTTL;
115+
113116
@Override
114117
public Integer call() throws Exception {
115118
source = normalize(source, FileType.RDB, spec, "Invalid options: '--source=<source>'");
116119
Configure configure = Configure.bind();
117-
120+
if (ignoreKeysWithTTL) {
121+
configure.setIgnoreKeysWithTTL(true);
122+
}
123+
118124
if (exclusive.migrate != null) {
119125
RedisURI uri = new RedisURI(exclusive.migrate);
120126

src/main/java/com/moilioncircle/redis/rdb/cli/conf/Configure.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ public Properties properties() {
290290
* scan step
291291
*/
292292
private int scanStep = 512;
293+
294+
/**
295+
* ignore keys with ttl set
296+
*/
297+
private boolean ignoreKeysWithTTL = false;
298+
299+
public boolean getIgnoreKeysWithTTL() {
300+
return this.ignoreKeysWithTTL;
301+
}
302+
303+
public void setIgnoreKeysWithTTL(boolean choice) {
304+
this.ignoreKeysWithTTL = choice;
305+
}
293306

294307
public int getBatchSize() {
295308
return batchSize;

src/main/java/com/moilioncircle/redis/rdb/cli/ext/rmt/SingleRdbVisitor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public class SingleRdbVisitor extends AbstractRmtRdbVisitor implements EventList
6363
private volatile byte[] evalSha;
6464
private final Configuration conf;
6565
private ThreadLocal<XEndpoint> endpoint = new ThreadLocal<>();
66+
67+
private int totalKeysWithTTL = 0;
6668

6769
//noinspection ThisEscapedInObjectConstruction
6870
public SingleRdbVisitor(Replicator replicator, Configure configure, Filter filter, RedisURI uri, boolean replace, boolean legacy) throws Exception {
@@ -108,14 +110,19 @@ public void retry(DumpKeyValuePair dkv, int times) {
108110
logger.trace("sync rdb event [{}], times {}", new String(dkv.getKey()), times);
109111
try {
110112
DB db = dkv.getDb();
111-
112113
int index;
113114
if (db != null && (index = (int) db.getDbNumber()) != endpoint.get().getDB()) {
114115
endpoint.get().select(true, index);
115116
}
116117

117118
byte[] expire = ZERO;
118119
if (dkv.getExpiredMs() != null) {
120+
if (configure.getIgnoreKeysWithTTL()) {
121+
totalKeysWithTTL += 1;
122+
return; // ignore keys with ttl
123+
}
124+
125+
119126
long ms = dkv.getExpiredMs() - System.currentTimeMillis();
120127
if (ms <= 0) {
121128
MONITOR.add(ENDPOINT_FAILURE, "expired", 1);

0 commit comments

Comments
 (0)