From 2f904c7aeca354d4e84310eb53a774d327d35d1e Mon Sep 17 00:00:00 2001 From: pengtao Date: Wed, 17 Jul 2019 11:08:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ad_interface_tornado.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) 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):