From 5349c6b9f23afb8ae93f45616eba488346b99b10 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 31 Aug 2020 19:10:29 +0800 Subject: [PATCH] 1 --- tools/migratedb/6000/redis.json | 4 ++-- tools/migratedb/common/redis_rule.json | 4 +++- tools/migratedb/migratedb.py | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/migratedb/6000/redis.json b/tools/migratedb/6000/redis.json index c2754a2..e0d8e02 100644 --- a/tools/migratedb/6000/redis.json +++ b/tools/migratedb/6000/redis.json @@ -2,8 +2,8 @@ { "instance_id" : 1, "host" : "127.0.0.1", - "port" : 3306, + "port" : 6379, "user" : "root", - "passwd" : "keji178" + "passwd" : "" } ] diff --git a/tools/migratedb/common/redis_rule.json b/tools/migratedb/common/redis_rule.json index 41b42e6..fcc63af 100644 --- a/tools/migratedb/common/redis_rule.json +++ b/tools/migratedb/common/redis_rule.json @@ -1,3 +1,5 @@ [ - + { + "key_prefix": "" + } ] diff --git a/tools/migratedb/migratedb.py b/tools/migratedb/migratedb.py index 6e9a67e..d3a8d93 100644 --- a/tools/migratedb/migratedb.py +++ b/tools/migratedb/migratedb.py @@ -37,17 +37,20 @@ def scanKeys(r, key_prefix, matched_keys): #end while cursor def saveKeys(r, keys, curr_file): + print(keys) for key in keys: data = r.get(key) + curr_file.write(json.dumps({'key': key, 'data':data}) + '\n') def exportRedis(context, redis_conf, redis_rule_conf): - curr_file = open(context['out_dir', 'w']) + curr_file = open(context['out_dir'] + context['channel'] + '.redis', 'w') for conf in redis_conf: r = redis.Redis(host = conf['host'], port = conf['port'], password = conf['passwd'], charset = 'utf8' ) + print(r) for rule in redis_rule_conf: matched_keys = {} scanKeys(r, rule['key_prefix'], matched_keys) @@ -60,6 +63,7 @@ def main(): os.mkdir(CONFIG_DIR + 'out/') if not os.path.exists(CONFIG_DIR + 'out/' + context['channel']): os.mkdir(CONFIG_DIR + 'out/' + context['channel']) + context['out_dir'] = CONFIG_DIR + 'out/' + context['channel'] + '/' db_conf = json.loads(open(CONFIG_DIR + context['channel'] + '/mysql.json', 'r').read()) redis_conf = json.loads(open(CONFIG_DIR + context['channel'] + '/redis.json', 'r').read()) db_rule_conf = json.loads(open(CONFIG_DIR + 'common/mysql_rule.json', 'r').read())