From 83e78f2e2fd4b6602e760ec914ded49e01ab7982 Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 28 Oct 2020 09:26:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8D=95=E4=B8=80=E4=B8=BB?= =?UTF-8?q?=E6=9C=BA=E7=9A=84=E9=9B=86=E7=BE=A4=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/redis/core/RedisDatabaseConnection.java | 15 +++++++++++++-- .../com/fr/plugin/db/redis/core/RedisPool.java | 6 ++++-- .../plugin/db/redis/core/RedisTableDataModel.java | 1 - .../plugin/db/redis/ui/RedisConnectionPane.java | 12 ++++++++++-- .../fr/plugin/db/redis/locale/redis.properties | 1 + .../plugin/db/redis/locale/redis_en_US.properties | 1 + .../plugin/db/redis/locale/redis_zh_CN.properties | 11 ++++++----- 7 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java b/src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java index 63e2c4e..6d78f5b 100755 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java +++ b/src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java @@ -26,6 +26,7 @@ public class RedisDatabaseConnection extends BaseConnection { private Conf host = HolderKit.simple(StringKit.EMPTY); private Conf port = HolderKit.simple(String.valueOf(DEFAULT_REDIS_PORT)); private Conf password = HolderKit.simple(StringKit.EMPTY); + private Conf cluster = HolderKit.simple(false); public RedisDatabaseConnection() { @@ -55,6 +56,13 @@ public class RedisDatabaseConnection extends BaseConnection { this.password.set(password); } + public boolean isCluster() { + return cluster.get(); + } + + public void setCluster(boolean cluster) { + this.cluster.set(cluster); + } @Override public void testConnection() throws Exception { @@ -71,7 +79,7 @@ public class RedisDatabaseConnection extends BaseConnection { } public Redis createRedisClient() { - return RedisPool.getFinal(getHost(), getPort(), getPassword()); + return RedisPool.getFinal(isCluster(), getHost(), getPort(), getPassword()); } @Override @@ -151,6 +159,7 @@ public class RedisDatabaseConnection extends BaseConnection { if (StringKit.isNotEmpty(pwd)) { setPassword(SecurityKit.encrypt(pwd)); } + setCluster(reader.getAttrAsBoolean("cluster", false)); } } } @@ -164,15 +173,17 @@ public class RedisDatabaseConnection extends BaseConnection { if (StringKit.isNotEmpty(getPassword())) { writer.attr("password", SecurityKit.decrypt(getPassword())); } + writer.attr("cluster", isCluster()); writer.end(); } @Override public Object clone() throws CloneNotSupportedException { - com.fr.plugin.db.redis.core.RedisDatabaseConnection cloned = (com.fr.plugin.db.redis.core.RedisDatabaseConnection) super.clone(); + com.fr.plugin.db.redis.core.RedisDatabaseConnection cloned = (RedisDatabaseConnection) super.clone(); cloned.host = (Conf) host.clone(); cloned.port = (Conf) port.clone(); cloned.password = (Conf) password.clone(); + cloned.cluster = (Conf) cluster.clone(); return cloned; } } \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisPool.java b/src/main/java/com/fr/plugin/db/redis/core/RedisPool.java index b7aa12a..5198d8a 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisPool.java +++ b/src/main/java/com/fr/plugin/db/redis/core/RedisPool.java @@ -61,9 +61,11 @@ public class RedisPool { jedisPoolMap.clear(); } - public static Redis getFinal(String host, String port, String password) { + public static Redis getFinal(boolean isCluster, String host, String port, String password) { List> pairs = findAllHostAndPassword(host, port); - if (pairs.size() == 1) { + if (isCluster) { + return pool.getJedisCluster(pairs, password); + } else if (pairs.size() == 1) { return pool.getStandaloneResource(pairs.get(0), password); } else { return pool.getJedisCluster(pairs, password); diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java b/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java index 3709c0d..5d9317a 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java +++ b/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java @@ -34,7 +34,6 @@ public class RedisTableDataModel extends BaseDataModel { long start = System.currentTimeMillis(); DataWrapper wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redis.getClient(), query, rowCount); LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start); - wrapper.transform(script); data = wrapper.getData(); columnNames = wrapper.getColumnNames(); } catch (Exception e) { diff --git a/src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java b/src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java index 33f3bfa..9e3570f 100755 --- a/src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java +++ b/src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java @@ -4,6 +4,7 @@ import com.fanruan.api.conf.ConfigurationKit; import com.fanruan.api.design.DesignKit; import com.fanruan.api.design.ui.component.UIActionLabel; import com.fanruan.api.design.ui.component.UIButton; +import com.fanruan.api.design.ui.component.UICheckBox; import com.fanruan.api.design.ui.component.UILabel; import com.fanruan.api.design.ui.component.UIPasswordField; import com.fanruan.api.design.ui.component.UITextField; @@ -31,6 +32,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane