diff --git a/ad_interface_tornado.py b/ad_interface_tornado.py index 69469e0..aa5b7ab 100644 --- a/ad_interface_tornado.py +++ b/ad_interface_tornado.py @@ -59,34 +59,20 @@ def send_cache_data(): for line in all: key = f"ad::{line.get('gameid', 0)}::{line.get('locationid', 0)}" if my_redis.exists(key): - my_redis.sadd(key, line['id']) - log.info(f"add{line['id']} to {key} !") - # 检查num是否已达到设定数值 num = my_redis.get(f"ad::{line['id']}::num") if not num: num = 0 - if line['ad_num'] > 0 and line['ad_num'] <= num: - # 该广告已播放达到次数,从缓存中清除 - my_redis.srem(key, line['id']) - # 清理广告详细记录 - my_redis.expire(f"ad::{line['id']}::info", 0) - log.info(f"remove {line['id']} from {key} and expire key ad::{line['id']::info}") + if line['ad_num'] == 0 or line['ad_num'] > num: + my_redis.sadd(key, line['id']) + my_redis.expire(key, 120) + log.info(f"add {line['id']} to {key} !") else: - log.info(f"add {line['id']} to {key} !") my_redis.sadd(key, line['id']) + my_redis.expire(key, 120) + log.info(f"add {line['id']} to {key} !") if not my_redis.exists(f"ad::{line['id']}::info"): my_redis.hmset(f"ad::{line['id']}::info", line) - - remove_sql = f"select id,gameid,locationid from ad where '{now}'>=end_time" - rm_data = mydb.query(remove_sql) - if rm_data: - for line in rm_data: - try: - id, gameid, locationid = line - my_redis.srem(f"ad::{gameid}::{locationid}", id) - log.info(f"remove expire ad {id}!") - except Exception: - log.error("split data from db failed!", exc_info=True) + my_redis.expire(f"ad::{line['id']}::info", 3600 * 24) class DispatchHandler(tornado.web.RequestHandler):