From 7f60997a58809cdbe91109cf0ccbdbf8c4442d91 Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Sun, 18 May 2025 13:09:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=BA=A7=E5=88=AB=202=20=E7=9A=84=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E4=BB=A5=E5=A2=9E=E5=8A=A0=E6=9C=80=E5=A4=A7=E9=A1=B5?= =?UTF-8?q?=E6=95=B0=E5=92=8C=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/DB.py b/DB.py index 4c77b0c..d7ca25f 100644 --- a/DB.py +++ b/DB.py @@ -6,8 +6,8 @@ import time class DBVidcon: _MYSQL_CONF = { - "host": "192.144.230.75", # "127.0.0.1", # - "port": 3306, # 3307, # + "host": "192.144.230.75", # "127.0.0.1", # + "port": 3306, # 3307, # "user": "db_vidcon", "password": "rexdK4fhCCiRE4BZ", "database": "db_vidcon", @@ -15,8 +15,8 @@ class DBVidcon: "cursorclass": pymysql.cursors.DictCursor, } _REDIS_CONF = { - "host": "192.144.230.75", # "127.0.0.1", # - "port": 6379, # 6380, # + "host": "192.144.230.75", # "127.0.0.1", # + "port": 6379, # 6380, # "password": "qwert@$123!&", "decode_responses": True, } @@ -268,3 +268,23 @@ class DBVidcon: else: break return proxy + + def queues_empty(self) -> bool: + """ + 判断 urgent_list_key 和 list_key 两个队列是否都为空。 + 如果都空,返回 True;只要有一个不空,就返回 False。 + """ + # 注意:redis.llen 返回 int + return ( + self.redis.llen(self.urgent_list_key) == 0 + and self.redis.llen(self.list_key) == 0 + ) + + def pop_error_item(self): + """ + 从 error_list_key 中弹出一个错误记录(lpop), + 如果队列为空,返回 None。 + """ + item = self.redis.lpop(self.error_list_key) + # 如果你存入的是 JSON 字符串,可以在这里做一次反序列化: + return json.loads(item) if item is not None else None