# log 数据库连接 class LogMysql(object): conn = None cursor = None def __init__(self): self.conn = pymysql.connect(host='', user='', password='', database='log', charset='utf8') self.cursor = self.conn.cursor() # 为了方便使用一般会选择将查询结果加上字段名称以字典组的方式返回查询结果 def dict_fetchall(self): "Return all rows from a cursor as a dict" # 获取查询字段 columns = [col[0] for col in self.cursor.description] print(columns) return [dict(zip(columns, row)) for row in self.cursor.fetchall()] # 获取表列表 def get_table_list(self): # 判断表是否存在 self.cursor.execute("SHOW TABLES") res = self.cursor.fetchall() table_list = [] for i in res: table_list.append(i[0]) # print("table_list", table_list) return table_list # redis主库 class Redis(object): conn = None def __init__(self): poll = redis.ConnectionPool(host='192.168.5.219', port=6379, db=14, password='root1234@A') # 本地测试 # poll = redis.ConnectionPool(host='192.168.10.10', port=7000, db=14) self.conn = redis.Redis(connection_pool=poll)