s
This commit is contained in:
commit
c700b16108
57
tools/migratedb/migratedb.py
Normal file
57
tools/migratedb/migratedb.py
Normal file
@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#!/usr/bin/python
|
||||
|
||||
import pymysql
|
||||
import hashlib
|
||||
import json
|
||||
import urllib.request
|
||||
import base64
|
||||
import time
|
||||
import datetime
|
||||
import redis
|
||||
import os
|
||||
import functools
|
||||
|
||||
CONFIG_DIR = '.'
|
||||
context = {
|
||||
'channel': 0,
|
||||
'dbname_prefix': ''
|
||||
}
|
||||
|
||||
def scanKeys(r, key_prefix, keys):
|
||||
scan_key = key_prefix + '*'
|
||||
cursor, keys = r.scan(0, scan_key, 1000)
|
||||
scan_count = 0
|
||||
while cursor != 0 or len(keys) > 0:
|
||||
#end
|
||||
keys = []
|
||||
if cursor != 0:
|
||||
cursor, keys = r.scan(cursor, scan_key, 1000)
|
||||
scan_count += 1
|
||||
if scan_count > 10000:
|
||||
break
|
||||
#end while cursor
|
||||
|
||||
def exportRedis(context, redis_conf, redis_rule_conf):
|
||||
for conf in redis_conf:
|
||||
r = redis.Redis(host = conf['host'],
|
||||
port = conf['port'],
|
||||
password = conf['passwd'],
|
||||
charset = 'utf8'
|
||||
)
|
||||
for rule in redis_rule_conf:
|
||||
keys = {}
|
||||
scanKeys(r, rule['key_prefix'], keys)
|
||||
#end for rule
|
||||
#end for conf
|
||||
|
||||
def main():
|
||||
global context
|
||||
db_conf = json.loads(open(CONFIG_DIR + '/mysql_list.json', 'r').read())
|
||||
redis_conf = json.loads(open(CONFIG_DIR + '/redis_list.json', 'r').read())
|
||||
db_rule_conf = json.loads(open(CONFIG_DIR + '/mysql_rule.json', 'r').read())
|
||||
redis_rule_conf = json.loads(open(CONFIG_DIR + '/redis_rule.json', 'r').read())
|
||||
exportRedis(context, redis_conf, redis_rule_conf)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
6
tools/migratedb/redis_rule.json
Normal file
6
tools/migratedb/redis_rule.json
Normal file
@ -0,0 +1,6 @@
|
||||
[
|
||||
{
|
||||
"key_prefix": "",
|
||||
"pattern": "md5"
|
||||
}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user