123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- """
- encoding: UTF-8
- @author:clx
- @file:config.py.py
- @time:2023/5/31 12:48
- """
- import json
- from minio import Minio
- from cacheout import Cache
- # 从配置文件读取设置
- class MinioOperate:
- def __init__(self):
- with open(r"D:\pythonProject\django\fastapi_01\config\config.json", "r") as f:
- self.__config = json.load(f)
- self.minio_client = None
- def link_minio(self):
- self.minio_client = Minio(**self.__config["minio"])
- return self.minio_client
- def create_bucket(self,buckets:[]):
- for bucket_name in buckets:
- if not self.minio_client.bucket_exists(bucket_name):
- try:
- self.minio_client.make_bucket(bucket_name)
- except Exception as e:
- print(f"Bucket creation failed: {e}")
- else:
- print(f"Bucket {bucket_name} already exists")
- class SetCache:
- def __init__(self,maxsize,ttl):
- self.cache = Cache(maxsize=maxsize, ttl=ttl)
- def get(self,uid):
- self.data = self.cache.get(uid)
- return self.data
- def add(self,uid,data):
- self.cache.add(uid,data)
|