Commit 3edac953 by 岳巧源

insert into redis

parent c33241e7
Showing with 13 additions and 6 deletions
......@@ -138,11 +138,11 @@ def update_ext_attr_by_class_ids(conf: dict):
"""
基于lie_shop_attr中的class_id来更新 “拓展” 属性
"""
host = conf["host"]
port = conf["port"]
user = conf["user"]
password = conf["password"]
database = conf["database"]
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)
select_sql = "select distinct class_id from lie_shop_attr"
cursor = db.cursor()
......@@ -174,6 +174,7 @@ def update_ext_attr_by_class_ids(conf: dict):
if flag != 1:
continue
attr_id = result["att_id"]
class_attr_mapping[class_id].append(attr_id)
attr_name = result["name"]
unit = result["val_unit"]
is_required = 1
......@@ -215,6 +216,7 @@ def update_ext_attr_by_class_ids(conf: dict):
print(insert_sql % (class_id, attr_id, attr_name, unit, enum_value, input_type, is_required, status, platform, create_time))
else:
update_sql = ""
insert_ext_attr_to_redis(class_attr_mapping, conf)
......@@ -239,6 +241,9 @@ def insert_ext_attr_to_redis(class_attr_map: dict, conf: dict):
for class_id in class_attr_map:
key = str(class_id)
attr_ids = class_attr_map[class_id]
if len(attr_ids) == 0:
# 为空的直接跳过
continue
value = json.dumps(attr_ids, ensure_ascii=False)
db.hset(name="jd_ext_attr", key=key, value=value)
......@@ -257,4 +262,5 @@ if __name__ == '__main__':
config = config_dev
elif environment == "prod":
config = config_prod
update_jd_attr_by_class(conf=config)
# update_jd_attr_by_class(conf=config)
# update_ext_attr_by_class_ids(conf=config)
\ No newline at end of file
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