From 521e3770b018b5b4f22eb67f3cb26c28e1104525 Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Sun, 29 Jun 2025 12:03:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=8E=9F=E5=AD=90?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=BB=A5=E6=B8=85=E7=A9=BA=E5=B9=B6=E5=86=99?= =?UTF-8?q?=E5=85=A5report=5Fqueue=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/DB.py b/DB.py index 06e7552..450efd3 100644 --- a/DB.py +++ b/DB.py @@ -254,11 +254,28 @@ class DBVidcon: @redis_retry(max_retries=3) def push_report(self, raws): - """向 report_queue 写入数据""" + """原子操作:清空列表并写入新数据""" if isinstance(raws, str): 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) def get_proxy_agent_dict(self) -> dict: