feat: base 增加获取修改单个缓存的接口
This commit is contained in:
parent
90a54d2279
commit
0e4ce09766
|
|
@ -2,7 +2,7 @@ from django.urls import path
|
|||
from apps.ops.views import (DrfRequestLogViewSet, CpuView, MemoryView, DiskView, DbBackupDeleteView,
|
||||
LogView, LogDetailView,
|
||||
DbBackupView, ReloadClientGit, ReloadServerGit, ReloadServerOnly,
|
||||
BackupDatabase, BackupMedia, TlogViewSet, CeleryInfoView, RedisInfoView)
|
||||
BackupDatabase, BackupMedia, TlogViewSet, CeleryInfoView, RedisInfoView, CacheView)
|
||||
|
||||
API_BASE_URL = 'api/ops/'
|
||||
HTML_BASE_URL = 'ops/'
|
||||
|
|
@ -21,6 +21,7 @@ urlpatterns = [
|
|||
path(API_BASE_URL + 'server/disk/', DiskView.as_view()),
|
||||
path(API_BASE_URL + 'celery/', CeleryInfoView.as_view()),
|
||||
path(API_BASE_URL + 'redis/', RedisInfoView.as_view()),
|
||||
path(API_BASE_URL + 'cache/<str:key>/', CacheView.as_view()),
|
||||
path(API_BASE_URL + 'request_log/',
|
||||
DrfRequestLogViewSet.as_view({'get': 'list'}), name='requestlog_view'),
|
||||
path(API_BASE_URL + 'tlog/',
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from rest_framework.permissions import IsAdminUser
|
|||
from drf_yasg.utils import swagger_auto_schema
|
||||
from apps.ops.service import ServerService, CeleryMonitor, RedisMonitor
|
||||
from server.settings import BACKUP_PATH
|
||||
from django.core.cache import cache
|
||||
# Create your views here.
|
||||
|
||||
|
||||
|
|
@ -229,6 +230,19 @@ class DbBackupView(APIView):
|
|||
return Response(items)
|
||||
|
||||
|
||||
class CacheView(APIView):
|
||||
permission_classes = [IsAdminUser]
|
||||
|
||||
@swagger_auto_schema(operation_summary="获取value", responses={204: None})
|
||||
def get(self, request, key):
|
||||
return Response(cache.get(key, None))
|
||||
|
||||
@swagger_auto_schema(operation_summary="修改value", responses={204: None})
|
||||
def post(self, request, key):
|
||||
if "value" in request.data and request.data["value"] is not None:
|
||||
cache.set(key, request.data.get("value"))
|
||||
return Response()
|
||||
|
||||
class DrfRequestLogViewSet(ListModelMixin, CustomGenericViewSet):
|
||||
"""list:请求日志
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue