添加接口示例
This commit is contained in:
parent
41def5da6c
commit
2f904c7aec
@ -59,34 +59,20 @@ def send_cache_data():
|
|||||||
for line in all:
|
for line in all:
|
||||||
key = f"ad::{line.get('gameid', 0)}::{line.get('locationid', 0)}"
|
key = f"ad::{line.get('gameid', 0)}::{line.get('locationid', 0)}"
|
||||||
if my_redis.exists(key):
|
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")
|
num = my_redis.get(f"ad::{line['id']}::num")
|
||||||
if not num:
|
if not num:
|
||||||
num = 0
|
num = 0
|
||||||
if line['ad_num'] > 0 and line['ad_num'] <= num:
|
if line['ad_num'] == 0 or line['ad_num'] > num:
|
||||||
# 该广告已播放达到次数,从缓存中清除
|
my_redis.sadd(key, line['id'])
|
||||||
my_redis.srem(key, line['id'])
|
my_redis.expire(key, 120)
|
||||||
# 清理广告详细记录
|
log.info(f"add {line['id']} to {key} !")
|
||||||
my_redis.expire(f"ad::{line['id']}::info", 0)
|
|
||||||
log.info(f"remove {line['id']} from {key} and expire key ad::{line['id']::info}")
|
|
||||||
else:
|
else:
|
||||||
log.info(f"add {line['id']} to {key} !")
|
|
||||||
my_redis.sadd(key, line['id'])
|
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"):
|
if not my_redis.exists(f"ad::{line['id']}::info"):
|
||||||
my_redis.hmset(f"ad::{line['id']}::info", line)
|
my_redis.hmset(f"ad::{line['id']}::info", line)
|
||||||
|
my_redis.expire(f"ad::{line['id']}::info", 3600 * 24)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class DispatchHandler(tornado.web.RequestHandler):
|
class DispatchHandler(tornado.web.RequestHandler):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user