This commit is contained in:
aozhiwei 2020-08-31 19:10:29 +08:00
parent 367bb814dd
commit 5349c6b9f2
3 changed files with 10 additions and 4 deletions

View File

@ -2,8 +2,8 @@
{
"instance_id" : 1,
"host" : "127.0.0.1",
"port" : 3306,
"port" : 6379,
"user" : "root",
"passwd" : "keji178"
"passwd" : ""
}
]

View File

@ -1,3 +1,5 @@
[
{
"key_prefix": ""
}
]

View File

@ -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())