diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/RedisController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/RedisController.java index 303e67184..500261cd5 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/RedisController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/RedisController.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.redis.core.RedisKeyDefine; import cn.iocoder.yudao.framework.redis.core.RedisKeyRegistry; import cn.iocoder.yudao.module.infra.controller.admin.redis.vo.RedisKeyRespVO; import cn.iocoder.yudao.module.infra.controller.admin.redis.vo.RedisMonitorRespVO; +import cn.iocoder.yudao.module.infra.controller.admin.redis.vo.RedisValuesRespVO; import cn.iocoder.yudao.module.infra.convert.redis.RedisConvert; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -12,13 +13,10 @@ import org.springframework.data.redis.connection.RedisServerCommands; import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.util.List; -import java.util.Properties; +import java.util.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -52,4 +50,42 @@ public class RedisController { return success(RedisConvert.INSTANCE.convertList(keyDefines)); } + @GetMapping("/get-key/{keyDefine}") + @ApiOperation("获得 Redis Key") +// @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") + public CommonResult> getKeyDefineKeys(@PathVariable("keyDefine") String keyDefine) { + Set Keys = stringRedisTemplate.keys(keyDefine + "*"); + return success(Keys); + } + + @DeleteMapping("/clear-key/{keyDefine}") + @ApiOperation("获得 Redis Key") +// @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") + public CommonResult clearKeyDefineKeys(@PathVariable("keyDefine") String keyDefine) { + stringRedisTemplate.delete(Objects.requireNonNull(stringRedisTemplate.keys(keyDefine + "*"))); + return success(Boolean.TRUE); + } + +// @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping("/get-key/{cacheName}/{cacheKey}") + public CommonResult getKeyValue(@PathVariable("cacheName") String cacheName, @PathVariable("cacheKey") String cacheKey) { + String cacheValue = stringRedisTemplate.opsForValue().get(cacheKey); + return success(new RedisValuesRespVO(cacheName, cacheKey, cacheValue)); + } + +// @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @DeleteMapping("/clearCacheKey/{cacheKey}") + public CommonResult clearCacheKey(@PathVariable String cacheKey) { + stringRedisTemplate.delete(cacheKey); + return success(Boolean.TRUE); + } + +// @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @DeleteMapping("/clearCacheAll") + public CommonResult clearCacheAll() { + Collection cacheKeys = stringRedisTemplate.keys("*"); + stringRedisTemplate.delete(cacheKeys); + return success(Boolean.TRUE); + } + } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/vo/RedisValuesRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/vo/RedisValuesRespVO.java new file mode 100644 index 000000000..d6f2627bc --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/vo/RedisValuesRespVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.infra.controller.admin.redis.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; + +@ApiModel("管理后台 - Redis Key Value onse VO") +@Data +@Builder +public class RedisValuesRespVO { + + @ApiModelProperty(value = "oauth2_access_token:%s", required = true, example = "String") + private String keyTemplate; + + @ApiModelProperty(value = "c5f6990767804a928f4bb96ca249febf", required = true, example = "String") + private String key; + + @ApiModelProperty(required = true, example = "String") + private String value; + + public RedisValuesRespVO(String keyTemplate, String key, String value){ + this.keyTemplate = StringUtils.replace(keyTemplate, ":", ""); + this.key = StringUtils.replace(key, keyTemplate, ""); + this.value = value; + } + + +} diff --git a/yudao-ui-admin/src/api/infra/redis.js b/yudao-ui-admin/src/api/infra/redis.js index 12ce00430..a4ea1b63c 100644 --- a/yudao-ui-admin/src/api/infra/redis.js +++ b/yudao-ui-admin/src/api/infra/redis.js @@ -8,10 +8,35 @@ export function getCache() { }) } -// TODO +// 获取模块 export function getKeyList() { return request({ url: '/infra/redis/get-key-list', method: 'get' }) } + +// 获取键名列表 +export function getKeyDefineKeys(keyDefine) { + return request({ + url: '/infra/redis/get-key/' + keyDefine, + method: 'get' + }) +} + +// 获取缓存内容 +export function getKeyValue(keyDefine, key) { + return request({ + url: '/infra/redis/get-key/' + keyDefine + "/" + key, + method: 'get' + }) +} + +// 根据键名删除缓存 +export function clearCacheKey(key) { + return request({ + url: '/infra/redis/clearCacheKey/' + key, + method: 'delete' + }) +} + diff --git a/yudao-ui-admin/src/views/infra/redis/index.vue b/yudao-ui-admin/src/views/infra/redis/index.vue index 1db94b9cc..53abf17b2 100644 --- a/yudao-ui-admin/src/views/infra/redis/index.vue +++ b/yudao-ui-admin/src/views/infra/redis/index.vue @@ -67,32 +67,133 @@ - + + + + + +
+ 键名列表 + +
+ + + + + + + + +
+
+ + + +
+ 缓存内容 + +
+ + + + + + + + + + + + + + + + + + + +
+
+
+
+