diff --git a/ad_tasks.py b/ad_tasks.py index 1c9bdb9..41157a6 100644 --- a/ad_tasks.py +++ b/ad_tasks.py @@ -24,8 +24,7 @@ def get_area_by_locationid(ldid): sql = f"select area from location where id={ldid}" data = mydb.query(sql) if data: - for line in data: - area.append(line[0]) + return data[0][0] else: log.error(f"get area from location failed!,sql={sql}") return area @@ -128,23 +127,22 @@ def send_cache_data(): locationid = json.loads(line.get('locationid')) for item in locationid: area = get_area_by_locationid(item) - for area_temp in area: - for one in area_temp.split(","): - key = f"ad::{line.get('gameid', 0)}::{line.get('channelid', 0)}::{one}::{item}" - if int(line['ad_num']) == 0: + for one in area.split(','): + key = f"ad::{line.get('gameid', 0)}::{line.get('channelid', 0)}::{one}::{item}" + if int(line['ad_num']) == 0: + 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): 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): - sadd_adkey(key, line, item) - else: - if my_redis.sismember(key, line['id']): - my_redis.srem(key, line['id']) - log.info(f"remove {line['id']} from {key}!") else: - log.error(f"get ad_num from mysql failed! ad_num={line['ad_num']}") + if my_redis.sismember(key, line['id']): + my_redis.srem(key, line['id']) + log.info(f"remove {line['id']} from {key}!") + else: + log.error(f"get ad_num from mysql failed! ad_num={line['ad_num']}") # 删除过期的数据 log.info("remove expire data from cache!") @@ -162,7 +160,7 @@ def send_cache_data(): id, gameid, channelid, locationid = line for item in locationid: area = get_area_by_locationid(item) - for one in area: + for one in area.split(','): key = f"ad::{line.get('gameid', 0)}::{line.get('channelid', 0)}::{one}::{item}" if my_redis.sismember(key, id): my_redis.srem(key, id)