feat: 实现原子操作以清空并写入report_queue数据
This commit is contained in:
parent
bae263df5d
commit
521e3770b0
23
DB.py
23
DB.py
@ -254,11 +254,28 @@ class DBVidcon:
|
|||||||
|
|
||||||
@redis_retry(max_retries=3)
|
@redis_retry(max_retries=3)
|
||||||
def push_report(self, raws):
|
def push_report(self, raws):
|
||||||
"""向 report_queue 写入数据"""
|
"""原子操作:清空列表并写入新数据"""
|
||||||
if isinstance(raws, str):
|
if isinstance(raws, str):
|
||||||
raws = [raws]
|
raws = [raws]
|
||||||
self.redis.rpush(self.report_list, *raws)
|
|
||||||
logger.info(f"[写入report] 已推入 {len(raws)} 条")
|
with self.redis.pipeline() as pipe:
|
||||||
|
# 开始事务
|
||||||
|
pipe.multi()
|
||||||
|
|
||||||
|
# 删除列表
|
||||||
|
pipe.delete(self.report_list)
|
||||||
|
|
||||||
|
# 如果有新数据,则推入
|
||||||
|
if raws:
|
||||||
|
pipe.rpush(self.report_list, *raws)
|
||||||
|
|
||||||
|
# 执行事务
|
||||||
|
pipe.execute()
|
||||||
|
|
||||||
|
if raws:
|
||||||
|
logger.info(f"[写入report] 原子操作:已清空并推入 {len(raws)} 条新数据")
|
||||||
|
else:
|
||||||
|
logger.info(f"[写入report] 原子操作:已清空列表")
|
||||||
|
|
||||||
@redis_retry(max_retries=3)
|
@redis_retry(max_retries=3)
|
||||||
def get_proxy_agent_dict(self) -> dict:
|
def get_proxy_agent_dict(self) -> dict:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user