Commit 28d46554 by larosa

add helper py

parent 79e5ed25
Showing with 28 additions and 6 deletions
"""
将redis中拓展数据更新到 mysql
"""
import json
import redis
import pymysql
config_dev = {
"mysql": {
......@@ -34,9 +36,29 @@ config_prod = {
}
}
def get_ext_attr_from_redis(conf: dict):
redis_host = conf["redis"]["host"]
redis_port = conf["redis"]["port"]
redis_password = conf["redis"]["password"]
redis_db = redis.Redis(host=redis_host, port=redis_port, password=redis_password)
redis_db.hget("jd_ext_attr", "")
"""
1 查找mysql中的platform = 1的数据,去redis中查到是否为拓展属性。
2 对比class_id 下面的attr_id 看是否存在redis中,存在就是拓展属性,否则就是非拓展。
3 拓展属性 is_ext字段改为 2,否则改为1
"""
def handle_data(conf: dict):
select_sql = "select class_id from lie_shop_class where platform = 1"
host = conf["mysql"]["host"]
port = conf["mysql"]["port"]
user = conf["mysql"]["user"]
password = conf["mysql"]["password"]
database = conf["mysql"]["database"]
db = pymysql.connect(host=host, port=port, user=user, password=password, database=database)
cursor = db.cursor()
cursor.execute(query=select_sql)
db_results = cursor.fetchall()
for i in range(len(db_results)):
class_id = db_results[i][0]
redis_host = conf["redis"]["host"]
redis_port = conf["redis"]["port"]
redis_password = conf["redis"]["password"]
redis_db = redis.Redis(host=redis_host, port=redis_port, password=redis_password)
class_id_str = str(class_id)
ans_redis = redis_db.hget("jd_ext_attr", class_id_str)
ans_arr = json.loads(ans_redis)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment