mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
style: 统一代码风格和格式 docs: 完善函数和方法的文档字符串 refactor(base_model): 移除冗余的表名和表参数生成方法 refactor(constant): 更新返回码注释格式 refactor(router_class): 添加路由处理器的详细文档 refactor(database): 完善数据库连接函数的文档 refactor(security): 添加认证类和方法的详细文档 refactor(validator): 更新验证器函数的文档格式 refactor(serialize): 优化序列化工具类的文档 refactor(response): 完善响应类的文档字符串 refactor(dependencies): 添加依赖函数的详细文档 refactor(initialize): 完善初始化脚本的文档 refactor(plugin): 添加生命周期和中间件注册的文档 refactor(service): 完善服务层方法的文档 refactor(controller): 添加控制器方法的详细文档 refactor(crud): 完善CRUD操作的文档字符串 refactor(schema): 简化模型类并移除冗余字段 refactor(param): 更新查询参数类的注释格式 refactor(template): 优化代码生成模板的格式 refactor(console): 添加控制台输出功能的实现 refactor(util): 完善工具函数的文档字符串
178 lines
5.6 KiB
Python
178 lines
5.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from fastapi.responses import JSONResponse
|
|
from redis.asyncio.client import Redis
|
|
|
|
from app.common.response import SuccessResponse
|
|
from app.core.exceptions import CustomException
|
|
from app.core.router_class import OperationLogRoute
|
|
from app.core.dependencies import AuthPermission, redis_getter
|
|
from app.core.logger import logger
|
|
from .service import CacheService
|
|
|
|
|
|
CacheRouter = APIRouter(route_class=OperationLogRoute, prefix="/cache", tags=["缓存监控"])
|
|
|
|
|
|
@CacheRouter.get(
|
|
'/info',
|
|
dependencies=[Depends(AuthPermission(['monitor:cache:query']))],
|
|
summary="获取缓存监控信息",
|
|
description="获取缓存监控信息"
|
|
)
|
|
async def get_monitor_cache_info_controller(
|
|
redis: Redis = Depends(redis_getter)
|
|
) -> JSONResponse:
|
|
"""
|
|
获取缓存监控统计信息
|
|
|
|
返回:
|
|
- JSONResponse: 包含缓存监控统计信息的JSON响应
|
|
"""
|
|
result = await CacheService.get_cache_monitor_statistical_info_service(redis=redis)
|
|
logger.info('获取缓存监控信息成功')
|
|
return SuccessResponse(data=result, msg='获取缓存监控信息成功')
|
|
|
|
|
|
@CacheRouter.get(
|
|
'/get/names',
|
|
dependencies=[Depends(AuthPermission(['monitor:cache:query']))],
|
|
summary="获取缓存名称列表",
|
|
description="获取缓存名称列表"
|
|
)
|
|
async def get_monitor_cache_name_controller() -> JSONResponse:
|
|
"""
|
|
获取缓存名称列表
|
|
|
|
返回:
|
|
- JSONResponse: 包含缓存名称列表的JSON响应
|
|
"""
|
|
result = await CacheService.get_cache_monitor_cache_name_service()
|
|
logger.info('获取缓存名称列表成功')
|
|
return SuccessResponse(data=result, msg='获取缓存名称列表成功')
|
|
|
|
|
|
@CacheRouter.get(
|
|
'/get/keys/{cache_name}',
|
|
dependencies=[Depends(AuthPermission(['monitor:cache:query']))],
|
|
summary="获取缓存键名列表",
|
|
description="获取缓存键名列表"
|
|
)
|
|
async def get_monitor_cache_key_controller(
|
|
cache_name: str,
|
|
redis: Redis = Depends(redis_getter)
|
|
) -> JSONResponse:
|
|
"""
|
|
获取指定缓存名称下的键名列表
|
|
|
|
参数:
|
|
- cache_name (str): 缓存名称
|
|
|
|
返回:
|
|
- JSONResponse: 包含缓存键名列表的JSON响应
|
|
"""
|
|
result = await CacheService.get_cache_monitor_cache_key_service(redis=redis, cache_name=cache_name)
|
|
logger.info(f'获取缓存{cache_name}的键名列表成功')
|
|
return SuccessResponse(data=result, msg=f'获取缓存{cache_name}的键名列表成功')
|
|
|
|
|
|
@CacheRouter.get(
|
|
'/get/value/{cache_name}/{cache_key}',
|
|
dependencies=[Depends(AuthPermission(['monitor:cache:query']))],
|
|
summary="获取缓存值",
|
|
description="获取缓存值"
|
|
)
|
|
async def get_monitor_cache_value_controller(
|
|
cache_name: str,
|
|
cache_key: str,
|
|
redis: Redis = Depends(redis_getter)
|
|
)-> JSONResponse:
|
|
"""
|
|
获取指定缓存键的值
|
|
|
|
参数:
|
|
- cache_name (str): 缓存名称
|
|
- cache_key (str): 缓存键
|
|
|
|
返回:
|
|
- JSONResponse: 包含缓存值的JSON响应
|
|
"""
|
|
result = await CacheService.get_cache_monitor_cache_value_service(redis=redis, cache_name=cache_name, cache_key=cache_key)
|
|
logger.info(f'获取缓存{cache_name}:{cache_key}的值成功')
|
|
return SuccessResponse(data=result, msg=f'获取缓存{cache_name}:{cache_key}的值成功')
|
|
|
|
|
|
@CacheRouter.delete(
|
|
'/delete/name/{cache_name}',
|
|
dependencies=[Depends(AuthPermission(['monitor:cache:delete']))],
|
|
summary="清除指定缓存名称的所有缓存",
|
|
description="清除指定缓存名称的所有缓存"
|
|
)
|
|
async def clear_monitor_cache_name_controller(
|
|
cache_name: str,
|
|
redis: Redis = Depends(redis_getter)
|
|
) -> JSONResponse:
|
|
"""
|
|
清除指定缓存名称下的所有缓存
|
|
|
|
参数:
|
|
- cache_name (str): 缓存名称
|
|
|
|
返回:
|
|
- JSONResponse: 包含清除结果的JSON响应
|
|
"""
|
|
result = await CacheService.clear_cache_monitor_cache_name_service(redis=redis, cache_name=cache_name)
|
|
if not result:
|
|
raise CustomException(msg='清除缓存失败', data=result)
|
|
logger.info(f'清除缓存{cache_name}成功')
|
|
return SuccessResponse(msg=f'{cache_name}对应键值清除成功', data=result)
|
|
|
|
|
|
@CacheRouter.delete(
|
|
'/delete/key/{cache_key}',
|
|
dependencies=[Depends(AuthPermission(['monitor:cache:delete']))],
|
|
summary="清除指定缓存键",
|
|
description="清除指定缓存键"
|
|
)
|
|
async def clear_monitor_cache_key_controller(
|
|
cache_key: str,
|
|
redis: Redis = Depends(redis_getter)
|
|
) -> JSONResponse:
|
|
"""
|
|
清除指定缓存键
|
|
|
|
参数:
|
|
- cache_key (str): 缓存键
|
|
|
|
返回:
|
|
- JSONResponse: 包含清除结果的JSON响应
|
|
"""
|
|
result = await CacheService.clear_cache_monitor_cache_key_service(redis=redis, cache_key=cache_key)
|
|
if not result:
|
|
raise CustomException(msg='清除缓存失败', data=result)
|
|
logger.info(f'清除缓存键{cache_key}成功')
|
|
return SuccessResponse(msg=f'{cache_key}清除成功', data=result)
|
|
|
|
|
|
@CacheRouter.delete(
|
|
'/delete/all',
|
|
dependencies=[Depends(AuthPermission(['monitor:cache:delete']))],
|
|
summary="清除所有缓存",
|
|
description="清除所有缓存"
|
|
)
|
|
async def clear_monitor_cache_all_controller(
|
|
redis: Redis = Depends(redis_getter)
|
|
) -> JSONResponse:
|
|
"""
|
|
清除所有缓存
|
|
|
|
返回:
|
|
- JSONResponse: 包含清除结果的JSON响应
|
|
"""
|
|
result = await CacheService.clear_cache_monitor_all_service(redis=redis)
|
|
if not result:
|
|
raise CustomException(msg='清除缓存失败', data=result)
|
|
logger.info('清除所有缓存成功')
|
|
return SuccessResponse(msg='所有缓存清除成功', data=result)
|