1
This commit is contained in:
parent
783638db51
commit
3538701702
@ -18,38 +18,32 @@ context = {
|
|||||||
'dbname_prefix': ''
|
'dbname_prefix': ''
|
||||||
}
|
}
|
||||||
|
|
||||||
def md5Str(data):
|
def scanKeys(r, key_prefix, keys):
|
||||||
m = hashlib.md5()
|
scan_key = key_prefix + '*'
|
||||||
m.update(data)
|
cursor, keys = r.scan(0, scan_key, 1000)
|
||||||
return m.hexdigest()
|
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 fetchAllAccount(context, db_conf, all_account_hash):
|
def exportRedis(context, redis_conf, redis_rule_conf):
|
||||||
for conf in db_conf:
|
for conf in redis_conf:
|
||||||
conn = pymysql.connect(host = conf['host'],
|
r = redis.Redis(host = conf['host'],
|
||||||
port = conf['port'],
|
port = conf['port'],
|
||||||
user = conf['user'],
|
password = conf['passwd'],
|
||||||
passwd = conf['passwd'],
|
charset = 'utf8'
|
||||||
db = context['dbname_prefix'] + str(conf['instance_id']),
|
|
||||||
charset = 'utf8'
|
|
||||||
)
|
)
|
||||||
cursor = conn.cursor()
|
for rule in redis_rule_conf:
|
||||||
last_idx = 0
|
keys = {}
|
||||||
while True:
|
scanKeys(r, rule['key_prefix'], keys)
|
||||||
cursor.execute('SELECT idx, accountid FROM user '
|
#end for rule
|
||||||
'WHERE idx > %s AND accountid LIKE "%s_\%" LIMIT 0, 10000;' %
|
#end for conf
|
||||||
(last_idx,
|
|
||||||
context['dbname_prefix']
|
|
||||||
))
|
|
||||||
has_data = False
|
|
||||||
for row in cursor:
|
|
||||||
has_data = True
|
|
||||||
all_account_hash[row[1]] = {
|
|
||||||
'md5' : md5Str(row[1])
|
|
||||||
}
|
|
||||||
if row[0] > last_idx:
|
|
||||||
last_idx = row[0]
|
|
||||||
if not has_data:
|
|
||||||
break
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global context
|
global context
|
||||||
@ -57,8 +51,7 @@ def main():
|
|||||||
redis_conf = json.loads(open(CONFIG_DIR + '/redis_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())
|
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())
|
redis_rule_conf = json.loads(open(CONFIG_DIR + '/redis_rule.json', 'r').read())
|
||||||
all_account_hash = {}
|
exportRedis(context, redis_conf, redis_rule_conf)
|
||||||
fetchAllAccount(context, db_conf, all_account_hash)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user