diff --git a/ad_tasks.py b/ad_tasks.py index 918474c..9b959c0 100644 --- a/ad_tasks.py +++ b/ad_tasks.py @@ -25,6 +25,7 @@ def get_area_by_locationid(ldid): data = mydb.query(sql) if data: for line in data: + pdb.set_trace() area.append(line[0]) else: log.error(f"get area from location failed!,sql={sql}") @@ -46,13 +47,23 @@ def split_ad_info(localtionid, line): return line +def sadd_adkey(key, line, item): + my_redis.sadd(key, line['id']) + my_redis.expire(key, 120) + info_key = f"adinfo::{line['id']}::info" + new_line = split_ad_info(item, line) + if new_line: + my_redis.hmset(info_key, new_line) + my_redis.expire(info_key, 60 * 60) + else: + log.error(f"split adinfo about locationid failed! localtionid={item} ") + def send_cache_data(): log.info("start update cache !") now = datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S") all = [] - ad_add_list = [] get_data_sql = f"""select id, name, @@ -79,7 +90,6 @@ def send_cache_data(): """ data = mydb.query(get_data_sql) - pdb.set_trace() if data: for line in data: if line: @@ -113,25 +123,18 @@ def send_cache_data(): for line in all: locationid = json.loads(line.get('locationid')) for item in locationid: + pdb.set_trace() area = get_area_by_locationid(item) for one in area: key = f"ad::{line.get('gameid', 0)}::{line.get('channelid', 0)}::{one}::{item}" if int(line['ad_num']) == 0: - ad_add_list.append(line) + sadd_adkey(key, line, item) elif int(line['ad_num']) > 0: num = my_redis.get(f"adnum::{line['id']}::num") if not num: num = 0 if int(line['ad_num']) > int(num): - my_redis.sadd(key, line['id']) - my_redis.expire(key, 120) - info_key = f"adinfo::{line['id']}::info" - new_line = split_ad_info(item, line) - if new_line: - my_redis.hmset(info_key, new_line) - my_redis.expire(info_key, 60 * 60) - else: - log.error(f"split adinfo about locationid failed! localtionid={item} ") + sadd_adkey(key, line, item) else: if my_redis.sismember(key, line['id']): my_redis.srem(key, line['id'])