From d3b990dec99c2fa456a76cc0513cdd6b633b4957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=A9=B0?= Date: Fri, 5 Nov 2021 17:19:24 +0800 Subject: [PATCH] commit for redis cluster batch delete key. --- README.md | 2 + derby.log | 4 +- .../controller/DataSinglesController.java | 19 +++++++- src/main/java/com/maxbill/tool/RedisUtil.java | 8 +++- src/main/resources/page/data-singles.html | 11 ++++- src/main/resources/script/data-singles.js | 47 +++++++++++++++++++ src/main/resources/style/data-singles.css | 2 +- 7 files changed, 87 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fcd0b43..175eff0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +#### 2021-11-05 更新 +1.由于redis cluster批量删除功能无法使用,在搜索框下增加一个批量删除框功能,适用于redis cluster环境。 #### 2021-10-25 更新 1.修复ssh登录问题,原逻辑中Jsch绑定本地端口后,Redis连接应使用本地IP及端口。 diff --git a/derby.log b/derby.log index aadb889..03efe03 100644 --- a/derby.log +++ b/derby.log @@ -1,6 +1,6 @@ ---------------------------------------------------------------- -Mon Oct 25 16:12:21 CST 2021: -Booting Derby version The Apache Software Foundation - Apache Derby - 10.13.1.1 - (1765088): instance a816c00e-017c-b681-ee87-000008d43b10 +Fri Nov 05 17:06:52 CST 2021: +Booting Derby version The Apache Software Foundation - Apache Derby - 10.13.1.1 - (1765088): instance a816c00e-017c-ef59-cd5c-00000834b498 on database directory C:\Users\DELL\.redis_plus\data with class loader sun.misc.Launcher$AppClassLoader@18b4aac2 Loaded from file:/D:/apache-maven-3.3.9/repository/org/apache/derby/derby/10.13.1.1/derby-10.13.1.1.jar java.vendor=Oracle Corporation diff --git a/src/main/java/com/maxbill/base/controller/DataSinglesController.java b/src/main/java/com/maxbill/base/controller/DataSinglesController.java index 23a7887..d6d3879 100644 --- a/src/main/java/com/maxbill/base/controller/DataSinglesController.java +++ b/src/main/java/com/maxbill/base/controller/DataSinglesController.java @@ -105,7 +105,24 @@ public String treeData(String id, int index, int page, String pattern) { try { Jedis jedis = getCurrentJedisObject(); if (null != jedis) { - return getOkByJson(RedisUtil.getKeyTree(jedis, index, page, id, pattern)); + return getOkByJson(RedisUtil.getKeyTree(jedis, index, page, id, pattern, false)); + } else { + return disconnect(); + } + } catch (Exception e) { + return exception(e); + } + } + + /** + * 数据分页查询并且模糊删除 + */ + @SuppressWarnings("unused") + public String treeAndDeleteData(String id, int index, int page, String pattern) { + try { + Jedis jedis = getCurrentJedisObject(); + if (null != jedis) { + return getOkByJson(RedisUtil.getKeyTree(jedis, index, page, id, pattern, true)); } else { return disconnect(); } diff --git a/src/main/java/com/maxbill/tool/RedisUtil.java b/src/main/java/com/maxbill/tool/RedisUtil.java index 8b55ca7..dd1f2f8 100644 --- a/src/main/java/com/maxbill/tool/RedisUtil.java +++ b/src/main/java/com/maxbill/tool/RedisUtil.java @@ -435,7 +435,7 @@ public static long getKeysCount(Jedis jedis, int index, String pattern) { /** * 按条件获取分页数据 */ - public static List getKeyTree(Jedis jedis, int index, int page, String pid, String pattern) { + public static List getKeyTree(Jedis jedis, int index, int page, String pid, String pattern, boolean isDeleted) { long startTime = System.currentTimeMillis(); /** CRC16 cluster模式 keys命令和select命令是禁止的*/ if(!RedisUtil.isCluster(jedis)) { @@ -445,6 +445,12 @@ public static List getKeyTree(Jedis jedis, int index, int page, Strin pattern = "*"; } Set keySet = RedisUtil.getRedisKeys(pattern, jedis); + if(isDeleted && !"*".equals(pattern)) { + Optional.ofNullable(keySet).orElse(Collections.emptySet()).stream().forEach(e -> { + System.out.println("删除key:"+ e); + jedis.del(e); + }); + } long endTime = System.currentTimeMillis(); log.info("getKeyTree查询耗时:" + (endTime - startTime)); diff --git a/src/main/resources/page/data-singles.html b/src/main/resources/page/data-singles.html index 323f006..516df1e 100644 --- a/src/main/resources/page/data-singles.html +++ b/src/main/resources/page/data-singles.html @@ -41,12 +41,21 @@
+ type="text" placeholder="请输要检索的key表达式 *通配所有">
+
+
+ + +
+
diff --git a/src/main/resources/script/data-singles.js b/src/main/resources/script/data-singles.js index 520f124..6f21e18 100644 --- a/src/main/resources/script/data-singles.js +++ b/src/main/resources/script/data-singles.js @@ -320,6 +320,25 @@ function loadDbData(node, pattern) { } } +//加载数据 +function loadAndDeleteDbData(node, pattern) { + layer.load(2); + var json = dataSinglesRouter.treeAndDeleteData(node.id, node.index, node.page, pattern); + var data = JSON.parse(json); + layer.closeAll('loading'); + if (data.code === 200) { + var zTree = $.fn.zTree.getZTreeObj('keyTree' + node.index); + zTree.removeChildNodes(node); + zTree.addNodes(node, 0, data.data); + // zTree.expandAll(true); + } else { + layer.alert(data.msgs, { + skin: 'layui-layer-lan', + closeBtn: 0 + }); + } +} + //获取key信息 function getKeysInfo(order) { @@ -400,6 +419,34 @@ function loadLikeTree() { } } + +//模糊匹配 +function loadLikeDeleteTree() { + if (null == currNode0) { + var zTreeObj = $.fn.zTree.getZTreeObj("keyTree0"); + currNode0 = zTreeObj.getNodesByFilter(function (node) { + return node.level === 0 + }, true); + } + layer.load(2); + var pattern = $("#key-like-delete-input").val(); + var json = dataSinglesRouter.likeInit(currNode0.index, pattern); + var data = JSON.parse(json); + layer.closeAll('loading'); + if (data.code === 200) { + var ztreeObj = $.fn.zTree.init($("#keyTree" + currNode0.index), zTreeSetting, data.data); + currNode0 = ztreeObj.getNodesByFilter(function (node) { + return node.level === 0 + }, true); + loadAndDeleteDbData(currNode0, pattern); + } else { + layer.alert(data.msgs, { + skin: 'layui-layer-lan', + closeBtn: 0 + }); + } +} + //重命名key function renameKey() { if (null == currNode1) { diff --git a/src/main/resources/style/data-singles.css b/src/main/resources/style/data-singles.css index aaccc32..c3136e2 100644 --- a/src/main/resources/style/data-singles.css +++ b/src/main/resources/style/data-singles.css @@ -15,7 +15,7 @@ } .handle-left-full { - top: 120px; + top: 180px; left: 0px; float: left; width: 400px;