调整缓存生成逻辑
This commit is contained in:
parent
1d86bc8ba7
commit
39b9789d51
@ -59,21 +59,25 @@ def send_cache_data():
|
|||||||
# log.info(f"get data was {all}!\n")
|
# log.info(f"get data was {all}!\n")
|
||||||
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 line['ad_num'] > 0:
|
||||||
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 or line['ad_num'] > num:
|
if line['ad_num'] > num:
|
||||||
my_redis.sadd(key, line['id'])
|
my_redis.sadd(key, line['id'])
|
||||||
my_redis.expire(key, 120)
|
my_redis.expire(key, 120)
|
||||||
log.info(f"add {line['id']} to {key} !")
|
log.info(f"add {line['id']} to {key} ,num was {line['ad_num']}!")
|
||||||
|
elif line['ad_num'] == 0:
|
||||||
|
my_redis.sadd(key, line['id'])
|
||||||
|
my_redis.expire(key, 120)
|
||||||
|
log.info(f"add {line['id']} to {key} ,num was unlimit !")
|
||||||
else:
|
else:
|
||||||
my_redis.sadd(key, line['id'])
|
log.error(f"get ad_num from mysql failed! ad_num={line['ad_num']}")
|
||||||
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)
|
my_redis.expire(f"ad::{line['id']}::info", 3600 * 24 * 7)
|
||||||
|
log.info(f"add ad::{line['id']}::info to redis!")
|
||||||
|
|
||||||
|
|
||||||
class DispatchHandler(tornado.web.RequestHandler):
|
class DispatchHandler(tornado.web.RequestHandler):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user