From fa31d232264004949ce11fc37692f9bfbc93f3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8A=93=E8=9B=99=E5=B8=88?= <770492966@qq.com> Date: Thu, 14 Jul 2022 19:05:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?redission=E5=A4=84=E7=90=86=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yml | 2 + .../src/main/resources/application-prod.yml | 2 + .../ruoyi/framework/config/RedisConfig.java | 3 ++ .../config/properties/RedissonProperties.java | 7 ++- .../framework/handler/KeyPrefixHandler.java | 43 +++++++++++++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/handler/KeyPrefixHandler.java diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index f9327f779..749f08691 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -138,6 +138,8 @@ spring: ssl: false redisson: + # redis key前缀 + keyPrefix: ruoyi-vue-plus # 线程池数量 threads: 4 # Netty线程池数量 diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index a42f4ad5b..3337036af 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -141,6 +141,8 @@ spring: ssl: false redisson: + # redis key前缀 + keyPrefix: ruoyi-vue-plus # 线程池数量 threads: 16 # Netty线程池数量 diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java index 38a871895..30fff169b 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java @@ -3,6 +3,7 @@ package com.ruoyi.framework.config; import cn.hutool.core.util.ObjectUtil; import com.fasterxml.jackson.databind.ObjectMapper; import com.ruoyi.framework.config.properties.RedissonProperties; +import com.ruoyi.framework.handler.KeyPrefixHandler; import lombok.extern.slf4j.Slf4j; import org.redisson.api.RedissonClient; import org.redisson.codec.JsonJacksonCodec; @@ -48,6 +49,7 @@ public class RedisConfig extends CachingConfigurerSupport { if (ObjectUtil.isNotNull(singleServerConfig)) { // 使用单机模式 config.useSingleServer() + .setNameMapper(new KeyPrefixHandler(redissonProperties.getKeyPrefix()))//设置redis key前缀 .setTimeout(singleServerConfig.getTimeout()) .setClientName(singleServerConfig.getClientName()) .setIdleConnectionTimeout(singleServerConfig.getIdleConnectionTimeout()) @@ -59,6 +61,7 @@ public class RedisConfig extends CachingConfigurerSupport { RedissonProperties.ClusterServersConfig clusterServersConfig = redissonProperties.getClusterServersConfig(); if (ObjectUtil.isNotNull(clusterServersConfig)) { config.useClusterServers() + .setNameMapper(new KeyPrefixHandler(redissonProperties.getKeyPrefix()))//设置redis key前缀 .setTimeout(clusterServersConfig.getTimeout()) .setClientName(clusterServersConfig.getClientName()) .setIdleConnectionTimeout(clusterServersConfig.getIdleConnectionTimeout()) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/RedissonProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/RedissonProperties.java index cd320eb50..eab746c8b 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/RedissonProperties.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/RedissonProperties.java @@ -18,7 +18,12 @@ import java.util.List; @Component @ConfigurationProperties(prefix = "redisson") public class RedissonProperties { - + + /** + * redis缓存key前缀 + */ + private String keyPrefix; + /** * 线程池数量,默认值 = 当前处理核数量 * 2 */ diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/KeyPrefixHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/KeyPrefixHandler.java new file mode 100644 index 000000000..28538055c --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/KeyPrefixHandler.java @@ -0,0 +1,43 @@ +package com.ruoyi.framework.handler; + +import com.ruoyi.common.utils.StringUtils; +import org.redisson.api.NameMapper; + +/* + * redis缓存key前缀处理 + * @author ye + * @create 2022/7/14 17:44 + */ +public class KeyPrefixHandler implements NameMapper { + + private final String keyPrefix; + + public KeyPrefixHandler(String keyPrefix) { + this.keyPrefix = keyPrefix + ":"; + } + + //增加前缀 + @Override + public String map(String name) { + if (StringUtils.isBlank(name)) { + return null; + } + if (!name.startsWith(keyPrefix)) { + return keyPrefix + name; + } else { + return name; + } + } + + //去除前缀 + @Override + public String unmap(String name) { + if (StringUtils.isBlank(name)) { + return null; + } + if (name.startsWith(keyPrefix)) { + return name.substring(keyPrefix.length()); + } + return name; + } +} From 65786c70a75a7b9dd0b1b777fbdd9faaa5152fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8A=93=E8=9B=99=E5=B8=88?= <770492966@qq.com> Date: Thu, 14 Jul 2022 19:14:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?redission=E5=A4=84=E7=90=86=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=97=A0=E5=89=8D=E7=BC=80=E5=88=99=E4=B8=8D=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/src/main/resources/application-dev.yml | 2 +- ruoyi-admin/src/main/resources/application-prod.yml | 2 +- .../com/ruoyi/framework/handler/KeyPrefixHandler.java | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 749f08691..88bc3a664 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -139,7 +139,7 @@ spring: redisson: # redis key前缀 - keyPrefix: ruoyi-vue-plus + keyPrefix: # 线程池数量 threads: 4 # Netty线程池数量 diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 3337036af..0987874fa 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -142,7 +142,7 @@ spring: redisson: # redis key前缀 - keyPrefix: ruoyi-vue-plus + keyPrefix: # 线程池数量 threads: 16 # Netty线程池数量 diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/KeyPrefixHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/KeyPrefixHandler.java index 28538055c..ddfa064e9 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/KeyPrefixHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/KeyPrefixHandler.java @@ -12,8 +12,9 @@ public class KeyPrefixHandler implements NameMapper { private final String keyPrefix; + //前缀为空 则返回空前缀 public KeyPrefixHandler(String keyPrefix) { - this.keyPrefix = keyPrefix + ":"; + this.keyPrefix = StringUtils.isBlank(keyPrefix) ? "" : keyPrefix + ":"; } //增加前缀 @@ -22,6 +23,9 @@ public class KeyPrefixHandler implements NameMapper { if (StringUtils.isBlank(name)) { return null; } + if (StringUtils.isBlank(keyPrefix)) { + return name; + } if (!name.startsWith(keyPrefix)) { return keyPrefix + name; } else { @@ -35,6 +39,9 @@ public class KeyPrefixHandler implements NameMapper { if (StringUtils.isBlank(name)) { return null; } + if (StringUtils.isBlank(keyPrefix)) { + return name; + } if (name.startsWith(keyPrefix)) { return name.substring(keyPrefix.length()); } From 3e512617282dca63a0145fe82ce79eec8c06e80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8A=93=E8=9B=99=E5=B8=88?= <770492966@qq.com> Date: Thu, 14 Jul 2022 21:20:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=B0=81=E8=A3=85=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/components/Editor/index.vue | 6 ++---- ruoyi-ui/src/components/FileUpload/index.vue | 6 ++---- ruoyi-ui/src/components/ImageUpload/index.vue | 6 ++---- ruoyi-ui/src/plugins/download.js | 6 +++--- ruoyi-ui/src/utils/auth.js | 6 ++++++ ruoyi-ui/src/utils/request.js | 3 ++- ruoyi-ui/src/views/demo/demo/index.vue | 4 ++-- ruoyi-ui/src/views/system/user/index.vue | 4 ++-- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/ruoyi-ui/src/components/Editor/index.vue b/ruoyi-ui/src/components/Editor/index.vue index 1f2e15ec2..057e09b5a 100644 --- a/ruoyi-ui/src/components/Editor/index.vue +++ b/ruoyi-ui/src/components/Editor/index.vue @@ -22,7 +22,7 @@ import Quill from "quill"; import "quill/dist/quill.core.css"; import "quill/dist/quill.snow.css"; import "quill/dist/quill.bubble.css"; -import { getToken } from "@/utils/auth"; +import { getHeader } from "@/utils/auth"; export default { name: "Editor", @@ -61,9 +61,7 @@ export default { data() { return { uploadUrl: process.env.VUE_APP_BASE_API + "/system/oss/upload", // 上传的图片服务器地址 - headers: { - Authorization: "Bearer " + getToken() - }, + headers: getHeader(), Quill: null, currentValue: "", options: { diff --git a/ruoyi-ui/src/components/FileUpload/index.vue b/ruoyi-ui/src/components/FileUpload/index.vue index e999f14f8..2650b1bc2 100644 --- a/ruoyi-ui/src/components/FileUpload/index.vue +++ b/ruoyi-ui/src/components/FileUpload/index.vue @@ -40,8 +40,8 @@