From 40954e4e4661449bda0108141294ab8691091183 Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Thu, 7 Jul 2022 12:38:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feature(Redis=E7=9B=91=E6=8E=A7):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=93=E5=AD=98=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/redis/RedisController.java | 46 ++++- .../admin/redis/vo/RedisValuesRespVO.java | 30 +++ yudao-ui-admin/src/api/infra/redis.js | 27 ++- .../src/views/infra/redis/index.vue | 173 ++++++++++++++++-- 4 files changed, 259 insertions(+), 17 deletions(-) create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/vo/RedisValuesRespVO.java 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 @@ - + + + + + +
+ 键名列表 + +
+ + + + + + + + +
+
+ + + +
+ 缓存内容 + +
+ + + + + + + + + + + + + + + + + + + +
+
+
+
+ From a7067ea6fd872e114640acb8ef949700436394b1 Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Thu, 7 Jul 2022 14:50:58 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feature(Redis=E7=9B=91=E6=8E=A7):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=93=E5=AD=98=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/redis/RedisController.java | 29 ++++++++++--------- yudao-ui-admin/src/api/infra/redis.js | 2 +- .../src/views/infra/redis/index.vue | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) 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 500261cd5..013145b96 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 @@ -43,7 +43,7 @@ public class RedisController { } @GetMapping("/get-key-list") - @ApiOperation("获得 Redis Key 列表") + @ApiOperation("获得 Redis Key 模板列表") @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") public CommonResult> getKeyList() { List keyDefines = RedisKeyRegistry.list(); @@ -51,37 +51,40 @@ public class RedisController { } @GetMapping("/get-key/{keyDefine}") - @ApiOperation("获得 Redis Key") -// @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") + @ApiOperation("获得 Redis keys 键名列表") + @PreAuthorize("@ss.hasPermission('infra:redis:get-key-define')") 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')") + @ApiOperation("删除 Redis Key 根据模板") + @PreAuthorize("@ss.hasPermission('infra:redis:clear-key-define')") 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) { + @GetMapping("/get-key/{keyDefine}/{cacheKey}") + @ApiOperation("获得 Redis key 内容") + @PreAuthorize("@ss.hasPermission('infra:redis:get-key-value')") + public CommonResult getKeyValue(@PathVariable("keyDefine") String keyDefine, @PathVariable("cacheKey") String cacheKey) { String cacheValue = stringRedisTemplate.opsForValue().get(cacheKey); - return success(new RedisValuesRespVO(cacheName, cacheKey, cacheValue)); + return success(new RedisValuesRespVO(keyDefine, cacheKey, cacheValue)); } -// @PreAuthorize("@ss.hasPermi('monitor:cache:list')") - @DeleteMapping("/clearCacheKey/{cacheKey}") + @DeleteMapping("/clear-key/{cacheKey}") + @ApiOperation("删除 Redis Key 根据key") + @PreAuthorize("@ss.hasPermission('infra:redis:clear-key-value')") public CommonResult clearCacheKey(@PathVariable String cacheKey) { stringRedisTemplate.delete(cacheKey); return success(Boolean.TRUE); } -// @PreAuthorize("@ss.hasPermi('monitor:cache:list')") - @DeleteMapping("/clearCacheAll") + @DeleteMapping("/clear-cache-all") + @ApiOperation(value="删除 所有缓存", notes="不使用该接口") + @PreAuthorize("@ss.hasPermission('infra:redis:clear-cache-all')") public CommonResult clearCacheAll() { Collection cacheKeys = stringRedisTemplate.keys("*"); stringRedisTemplate.delete(cacheKeys); diff --git a/yudao-ui-admin/src/api/infra/redis.js b/yudao-ui-admin/src/api/infra/redis.js index a4ea1b63c..2064dfc68 100644 --- a/yudao-ui-admin/src/api/infra/redis.js +++ b/yudao-ui-admin/src/api/infra/redis.js @@ -35,7 +35,7 @@ export function getKeyValue(keyDefine, key) { // 根据键名删除缓存 export function clearCacheKey(key) { return request({ - url: '/infra/redis/clearCacheKey/' + key, + url: '/infra/redis/clear-key/' + 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 53abf17b2..763f605ed 100644 --- a/yudao-ui-admin/src/views/infra/redis/index.vue +++ b/yudao-ui-admin/src/views/infra/redis/index.vue @@ -93,7 +93,7 @@ From 4263df3e93eafe33ab1c9ab37deb3d468bae9845 Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Thu, 7 Jul 2022 14:54:45 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feature(Redis=E7=9B=91=E6=8E=A7):=20?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/controller/admin/redis/RedisController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 013145b96..ccbfe9e6f 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 @@ -52,7 +52,7 @@ public class RedisController { @GetMapping("/get-key/{keyDefine}") @ApiOperation("获得 Redis keys 键名列表") - @PreAuthorize("@ss.hasPermission('infra:redis:get-key-define')") + @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") public CommonResult> getKeyDefineKeys(@PathVariable("keyDefine") String keyDefine) { Set Keys = stringRedisTemplate.keys(keyDefine + "*"); return success(Keys); @@ -60,7 +60,7 @@ public class RedisController { @DeleteMapping("/clear-key/{keyDefine}") @ApiOperation("删除 Redis Key 根据模板") - @PreAuthorize("@ss.hasPermission('infra:redis:clear-key-define')") + @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); @@ -68,7 +68,7 @@ public class RedisController { @GetMapping("/get-key/{keyDefine}/{cacheKey}") @ApiOperation("获得 Redis key 内容") - @PreAuthorize("@ss.hasPermission('infra:redis:get-key-value')") + @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") public CommonResult getKeyValue(@PathVariable("keyDefine") String keyDefine, @PathVariable("cacheKey") String cacheKey) { String cacheValue = stringRedisTemplate.opsForValue().get(cacheKey); return success(new RedisValuesRespVO(keyDefine, cacheKey, cacheValue)); @@ -76,7 +76,7 @@ public class RedisController { @DeleteMapping("/clear-key/{cacheKey}") @ApiOperation("删除 Redis Key 根据key") - @PreAuthorize("@ss.hasPermission('infra:redis:clear-key-value')") + @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") public CommonResult clearCacheKey(@PathVariable String cacheKey) { stringRedisTemplate.delete(cacheKey); return success(Boolean.TRUE); @@ -84,7 +84,7 @@ public class RedisController { @DeleteMapping("/clear-cache-all") @ApiOperation(value="删除 所有缓存", notes="不使用该接口") - @PreAuthorize("@ss.hasPermission('infra:redis:clear-cache-all')") + @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") public CommonResult clearCacheAll() { Collection cacheKeys = stringRedisTemplate.keys("*"); stringRedisTemplate.delete(cacheKeys); From a8ebc564721f4ed8b8d42035ef8f7509a2c3a67e Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Thu, 7 Jul 2022 15:01:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feature(Redis=E7=9B=91=E6=8E=A7):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/infra/controller/admin/redis/RedisController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ccbfe9e6f..9ef762d0c 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 @@ -58,7 +58,7 @@ public class RedisController { return success(Keys); } - @DeleteMapping("/clear-key/{keyDefine}") + @DeleteMapping("/clear-key-define/{keyDefine}") @ApiOperation("删除 Redis Key 根据模板") @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") public CommonResult clearKeyDefineKeys(@PathVariable("keyDefine") String keyDefine) { From c0b1f62afd4a3041583073a547b485aa0be18ea8 Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Fri, 8 Jul 2022 11:47:02 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix(Redis=E7=9B=91=E6=8E=A7):=20fix=20revie?= =?UTF-8?q?w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/redis/RedisController.java | 60 +++++++++++++------ ...esRespVO.java => RedisKeyValueRespVO.java} | 14 +++-- yudao-ui-admin/src/api/infra/redis.js | 10 ++-- .../src/views/infra/redis/index.vue | 6 +- 4 files changed, 58 insertions(+), 32 deletions(-) rename yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/vo/{RedisValuesRespVO.java => RedisKeyValueRespVO.java} (61%) 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 9ef762d0c..f83aa0c20 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 @@ -4,19 +4,25 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; 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.RedisKeyValueRespVO; 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; import org.springframework.data.redis.connection.RedisServerCommands; +import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisCallback; +import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.util.*; +import java.nio.charset.StandardCharsets; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -50,45 +56,61 @@ public class RedisController { return success(RedisConvert.INSTANCE.convertList(keyDefines)); } - @GetMapping("/get-key/{keyDefine}") + @GetMapping("/get-key-Defines") @ApiOperation("获得 Redis keys 键名列表") @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") - public CommonResult> getKeyDefineKeys(@PathVariable("keyDefine") String keyDefine) { - Set Keys = stringRedisTemplate.keys(keyDefine + "*"); - return success(Keys); + public CommonResult> getKeyDefines(@RequestParam("keyDefine") String keyDefine) { + Set keys = new HashSet<>(); + stringRedisTemplate.execute((RedisCallback>) connection -> { + try (Cursor cursor = connection.scan(ScanOptions.scanOptions() + .match(keyDefine + "*") + .count(Integer.MAX_VALUE).build())) { + while (cursor.hasNext()) { + keys.add(new String(cursor.next(), StandardCharsets.UTF_8)); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return keys; + }); + return success(keys); } - @DeleteMapping("/clear-key-define/{keyDefine}") + @DeleteMapping("/delete-key-defines") @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 + "*"))); + public CommonResult deleteKeyDefines(@RequestParam("keyDefine") String keyDefine) { + Set keys = stringRedisTemplate.keys(keyDefine + "*"); + if(keys != null && keys.isEmpty()){ + stringRedisTemplate.delete(keys); + } return success(Boolean.TRUE); } - @GetMapping("/get-key/{keyDefine}/{cacheKey}") + @GetMapping("/get-key-value") @ApiOperation("获得 Redis key 内容") @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") - public CommonResult getKeyValue(@PathVariable("keyDefine") String keyDefine, @PathVariable("cacheKey") String cacheKey) { + public CommonResult getKeyValue(@RequestParam("keyDefine") String keyDefine, @RequestParam("cacheKey") String cacheKey) { String cacheValue = stringRedisTemplate.opsForValue().get(cacheKey); - return success(new RedisValuesRespVO(keyDefine, cacheKey, cacheValue)); + return success(RedisKeyValueRespVO.of(keyDefine, cacheKey, cacheValue)); } - @DeleteMapping("/clear-key/{cacheKey}") + @DeleteMapping("/delete-key-value") @ApiOperation("删除 Redis Key 根据key") @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") - public CommonResult clearCacheKey(@PathVariable String cacheKey) { + public CommonResult deleteKeyValue(@RequestParam("cacheKey") String cacheKey) { stringRedisTemplate.delete(cacheKey); return success(Boolean.TRUE); } - @DeleteMapping("/clear-cache-all") + @DeleteMapping("/delete-cache-all") @ApiOperation(value="删除 所有缓存", notes="不使用该接口") @PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')") - public CommonResult clearCacheAll() { - Collection cacheKeys = stringRedisTemplate.keys("*"); - stringRedisTemplate.delete(cacheKeys); - return success(Boolean.TRUE); + public CommonResult deleteCacheAll() { + return success(stringRedisTemplate.execute((RedisCallback) connection -> { + connection.flushAll(); + return 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/RedisKeyValueRespVO.java similarity index 61% rename from yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/vo/RedisValuesRespVO.java rename to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/redis/vo/RedisKeyValueRespVO.java index d6f2627bc..7f186e659 100644 --- 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/RedisKeyValueRespVO.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.infra.controller.admin.redis.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import org.apache.commons.lang3.StringUtils; @@ -9,7 +10,8 @@ import org.apache.commons.lang3.StringUtils; @ApiModel("管理后台 - Redis Key Value onse VO") @Data @Builder -public class RedisValuesRespVO { +@AllArgsConstructor +public class RedisKeyValueRespVO { @ApiModelProperty(value = "oauth2_access_token:%s", required = true, example = "String") private String keyTemplate; @@ -20,10 +22,12 @@ public class RedisValuesRespVO { @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; + public static RedisKeyValueRespVO of(String keyTemplate, String key, String value){ + return RedisKeyValueRespVO.builder() + .keyTemplate(StringUtils.replace(keyTemplate, ":", "")) + .key(StringUtils.replace(key, keyTemplate, "")) + .value(value) + .build(); } diff --git a/yudao-ui-admin/src/api/infra/redis.js b/yudao-ui-admin/src/api/infra/redis.js index 2064dfc68..ab5ab0489 100644 --- a/yudao-ui-admin/src/api/infra/redis.js +++ b/yudao-ui-admin/src/api/infra/redis.js @@ -17,9 +17,9 @@ export function getKeyList() { } // 获取键名列表 -export function getKeyDefineKeys(keyDefine) { +export function getKeyDefines(keyDefine) { return request({ - url: '/infra/redis/get-key/' + keyDefine, + url: '/infra/redis/get-key-Defines?keyDefine=' + keyDefine, method: 'get' }) } @@ -27,15 +27,15 @@ export function getKeyDefineKeys(keyDefine) { // 获取缓存内容 export function getKeyValue(keyDefine, key) { return request({ - url: '/infra/redis/get-key/' + keyDefine + "/" + key, + url: '/infra/redis/get-key-value?keyDefine=' + keyDefine + "&cacheKey=" + key, method: 'get' }) } // 根据键名删除缓存 -export function clearCacheKey(key) { +export function deleteKeyValue(key) { return request({ - url: '/infra/redis/clear-key/' + key, + url: '/infra/redis/delete-key-value?cacheKey=' + 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 763f605ed..8c09b00bc 100644 --- a/yudao-ui-admin/src/views/infra/redis/index.vue +++ b/yudao-ui-admin/src/views/infra/redis/index.vue @@ -188,7 +188,7 @@