redis remove key 之前判断该key是否存在
This commit is contained in:
parent
a8d2e5975d
commit
3bd7da3a9f
@ -36,8 +36,9 @@ def send_cache_data():
|
||||
log.info(f"line was {line}")
|
||||
item = {}
|
||||
try:
|
||||
item['id'], item['name'], item['ad_num'], item['ad_title'], item['ad_body'], item['ad_image'], item['ad_url'], \
|
||||
item['ad_sort'], item['companyid'], item['locationid'], item['gameid'], item['appid'] = line
|
||||
item['id'], item['name'], item['ad_num'], item['ad_title'], item['ad_body'], item['ad_image'], item[
|
||||
'ad_url'], item['ad_sort'], item['companyid'], item['locationid'], item['gameid'], item[
|
||||
'appid'] = line
|
||||
all.append(item)
|
||||
except Exception:
|
||||
log.error("split data failed", exc_info=True)
|
||||
@ -51,8 +52,9 @@ def send_cache_data():
|
||||
if line:
|
||||
item = {}
|
||||
try:
|
||||
item['id'], item['name'], item['ad_num'], item['ad_title'], item['ad_body'], item['ad_image'], item['ad_url'], \
|
||||
item['ad_sort'], item['companyid'], item['locationid'], item['gameid'], item['appid'] = line
|
||||
item['id'], item['name'], item['ad_num'], item['ad_title'], item['ad_body'], item['ad_image'], item[
|
||||
'ad_url'], item['ad_sort'], item['companyid'], item['locationid'], item['gameid'], item[
|
||||
'appid'] = line
|
||||
all.append(item)
|
||||
except Exception:
|
||||
log.error("split data failed", exc_info=True)
|
||||
@ -72,6 +74,7 @@ def send_cache_data():
|
||||
n = int(line['ad_num']) - int(num)
|
||||
log.info(f"add {line['id']} to {key} ,num was {line['ad_num']},limit was {n}!")
|
||||
else:
|
||||
if my_redis.sismember(key, line['id']):
|
||||
my_redis.srem(key, line['id'])
|
||||
log.info(f"remove {line['id']} from {key}!")
|
||||
elif int(line['ad_num']) == 0:
|
||||
@ -95,6 +98,7 @@ def send_cache_data():
|
||||
try:
|
||||
id, gameid, locationid = line
|
||||
key = f"{gameid}:{locationid}"
|
||||
if my_redis.sismember(key, id):
|
||||
my_redis.srem(key, id)
|
||||
log.info(f"remove {id} from {key} success!")
|
||||
except Exception:
|
||||
|
Loading…
x
Reference in New Issue
Block a user