浏览代码

feat(redis-inspector): add CHANNEL, CATEGORY, and TAG to RedisInspectorGroupCode enum and update GROUP_PATTERNS

Dave 1 月之前
父节点
当前提交
1e77a0a844

+ 3 - 1
apps/box-mgnt-api/src/mgnt-backend/feature/redis-inspector/dto/scan-redis-keys.dto.ts

@@ -3,9 +3,11 @@ import { Type } from 'class-transformer';
 import { IsEnum, IsInt, IsOptional, IsString, Max, Min } from 'class-validator';
 
 export enum RedisInspectorGroupCode {
+  CHANNEL = 'CHANNEL',
+  CATEGORY = 'CATEGORY',
+  TAG = 'TAG',
   VIDEO = 'VIDEO',
   ADS = 'ADS',
-  MOVIE = 'MOVIE',
 }
 
 export class ScanRedisKeysDto {

+ 28 - 8
apps/box-mgnt-api/src/mgnt-backend/feature/redis-inspector/redis-inspector.service.ts

@@ -20,10 +20,13 @@ import { LatestVideosCacheBuilder } from '@box/core/cache/video/latest/latest-vi
 import { RecommendedVideosCacheBuilder } from '@box/core/cache/video/recommended/recommended-videos-cache.builder';
 
 const GROUP_PATTERNS: Record<RedisInspectorGroupCode, string> = {
+  [RedisInspectorGroupCode.CHANNEL]: 'box:app:channel*',
+  [RedisInspectorGroupCode.CATEGORY]: 'box:app:category*',
+  [RedisInspectorGroupCode.TAG]: 'box:app:tag*',
   [RedisInspectorGroupCode.VIDEO]: 'box:app:video*',
-  [RedisInspectorGroupCode.ADS]: 'box:app:ads*',
-  [RedisInspectorGroupCode.MOVIE]: 'box:app:movie*',
+  [RedisInspectorGroupCode.ADS]: 'box:app:adpool*',
 };
+const MAX_JSON_PARSE_BYTES = 2 * 1024 * 1024;
 
 @Injectable()
 export class RedisInspectorService {
@@ -141,17 +144,34 @@ export class RedisInspectorService {
     const byteLen = await this.redisService.strLen(key);
     const rawValue = (await this.redisService.get(key)) ?? '';
     const { text, truncated } = this.prepareStringPreview(rawValue);
+    const meta: Record<string, any> = { byteLen };
     const preview: Record<string, any> = {
       format: 'text',
       data: text,
     };
 
-    if (!truncated && text) {
-      const parsed = this.tryParseJson(text);
-      if (parsed !== undefined) {
-        preview.format = 'json';
-        preview.data = parsed;
+    const canParseJson = byteLen <= MAX_JSON_PARSE_BYTES;
+    const candidate = canParseJson ? this.tryParseJson(rawValue) : undefined;
+
+    if (candidate !== undefined && Array.isArray(candidate)) {
+      meta.itemCount = candidate.length;
+      preview.format = 'json';
+      preview.data = candidate.slice(0, 5);
+      if (candidate.length > 5) {
+        preview.truncated = true;
       }
+      return {
+        key,
+        type: 'string',
+        ttlSec,
+        meta,
+        preview,
+      };
+    }
+
+    if (!truncated && candidate !== undefined) {
+      preview.format = 'json';
+      preview.data = candidate;
     }
 
     if (truncated) {
@@ -162,7 +182,7 @@ export class RedisInspectorService {
       key,
       type: 'string',
       ttlSec,
-      meta: { byteLen },
+      meta,
       preview,
     };
   }

+ 33 - 0
prisma/mongo/seed-admin.ts

@@ -971,6 +971,39 @@ const MENU_SEEDS: SeedMenu[] = [
       noCache: 'menuList',
     },
   },
+  {
+    legacyId: 52,
+    legacyParentId: 42,
+    title: 'Redis监控',
+    type: 'MENU',
+    name: 'redisMonitor',
+    path: '/system/redisMonitor',
+    icon: 'i-carbon:list-boxes',
+    order: 4,
+    meta: {
+      title: 'Redis监控',
+      i18n: 'route.general.redisMonitor.list',
+      icon: 'i-carbon:list-boxes',
+    },
+  },
+  {
+    legacyId: 53,
+    legacyParentId: 52,
+    title: 'Redis列表',
+    type: 'SUBMENU',
+    name: 'redisList',
+    path: '/system/redisList',
+    icon: null,
+    componentKey: '@/views/system_mgnt/redisMonitor/list.vue',
+    order: 1,
+    meta: {
+      title: 'Redis列表',
+      i18n: 'route.general.redisMonitor.list',
+      sidebar: false,
+      breadcrumb: false,
+      cache: ['redisCreate', 'redisEdit'],
+    },
+  },
 ];
 
 // =============================================================================