diff --git a/.gitignore b/.gitignore index 65435b5..6ac12f0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ target config/ __pycache__/ res +out/ \ No newline at end of file diff --git a/tools/migratedb/migratedb.py b/tools/migratedb/migratedb.py index 64e6262..c72046a 100644 --- a/tools/migratedb/migratedb.py +++ b/tools/migratedb/migratedb.py @@ -39,7 +39,25 @@ def scanKeys(r, key_prefix, matched_keys): def saveKeys(r, keys, curr_file): for key in keys: data = r.get(key) - curr_file.write(json.dumps({'key': key, 'data':data}) + '\n') + expire = r.ttl(key) + curr_file.write(json.dumps( + { + 'cmd': 'set', + 'key': key, + 'data':data + } + ) + '\n') + curr_file.write(json.dumps( + { + 'cmd': 'expire', + 'key': key, + 'time': expire + } + ) + '\n') + if expire < 0: + print('[ERROR] ' + key + ' ttl < 0') + if expire > 3600 * 24: + print('[ERROR] ' + key + ' ttl > 3600 * 24') def exportRedis(context, redis_conf, redis_rule_conf): curr_file = open(context['out_dir'] + context['channel'] + '.redis', 'w') @@ -49,7 +67,6 @@ def exportRedis(context, redis_conf, redis_rule_conf): password = conf['passwd'], decode_responses = True ) - print(r) for rule in redis_rule_conf: matched_keys = {} scanKeys(r, rule['key_prefix'], matched_keys)