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