更改用户资料需要完善脚本
背景描述,由于最近在测试环境发现注册完善资料后会发生崩溃,研发由于调试需要大量需要完善资料的用户账号
但是手动注册账号比较耗时,遂编写此脚本以提高效率
代码如下:
# coding=utf-8import pymysqlfrom rediscluster import StrictRedisClusterdb = pymysql.connect(user="***", password="***", port=3306, db="***", host="***", charset="utf8")cur = db.cursor()def doSQL(sql): cur.execute(sql) db.commit()# 删除数据库记录doSQL("DELETE FROM account_bind WHERE uid=70006796;")doSQL("DELETE FROM account_login_record WHERE uid=70006796;")doSQL("DELETE FROM users WHERE uid=70006796;")cur.close()db.close()def redis_cluster(): redis_nodes = [{‘host‘: ‘47.91.110.137‘, ‘port‘: 7001}, {‘host‘: ‘47.91.110.137‘, ‘port‘: 7002}, {‘host‘: ‘47.91.110.137‘, ‘port‘: 7003} ] r = StrictRedisCluster(startup_nodes=redis_nodes, password=‘bwgfs127BWGFS127‘) # 删除Redis记录 print(r.hdel(‘erban_acc_bind‘, ‘70006796‘)) print(r.hdel(‘erban_acc_latest_login‘, ‘70006796‘)) print(r.hdel(‘erban_user_summary‘, ‘70006796‘)) print(r.hdel(‘erban_user‘, ‘70006796‘)) print(r.hdel(‘erban_user_erban_no‘, ‘3169352‘))redis_cluster()如需批量删除,可通过改写SQL语句实现如下:DELETE FROM account_bind WHERE uid IN (70006796,70006797);r.hdel(‘erban_acc_bind‘, [‘70006796‘,‘70006796‘])