Browse Source

支持单一主机的集群模式

pull/2/head
richie 4 years ago
parent
commit
83e78f2e2f
  1. 15
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java
  2. 6
      src/main/java/com/fr/plugin/db/redis/core/RedisPool.java
  3. 1
      src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java
  4. 12
      src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java
  5. 1
      src/main/resources/com/fr/plugin/db/redis/locale/redis.properties
  6. 1
      src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties
  7. 11
      src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties

15
src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java

@ -26,6 +26,7 @@ public class RedisDatabaseConnection extends BaseConnection {
private Conf<String> host = HolderKit.simple(StringKit.EMPTY); private Conf<String> host = HolderKit.simple(StringKit.EMPTY);
private Conf<String> port = HolderKit.simple(String.valueOf(DEFAULT_REDIS_PORT)); private Conf<String> port = HolderKit.simple(String.valueOf(DEFAULT_REDIS_PORT));
private Conf<String> password = HolderKit.simple(StringKit.EMPTY); private Conf<String> password = HolderKit.simple(StringKit.EMPTY);
private Conf<Boolean> cluster = HolderKit.simple(false);
public RedisDatabaseConnection() { public RedisDatabaseConnection() {
@ -55,6 +56,13 @@ public class RedisDatabaseConnection extends BaseConnection {
this.password.set(password); this.password.set(password);
} }
public boolean isCluster() {
return cluster.get();
}
public void setCluster(boolean cluster) {
this.cluster.set(cluster);
}
@Override @Override
public void testConnection() throws Exception { public void testConnection() throws Exception {
@ -71,7 +79,7 @@ public class RedisDatabaseConnection extends BaseConnection {
} }
public Redis createRedisClient() { public Redis createRedisClient() {
return RedisPool.getFinal(getHost(), getPort(), getPassword()); return RedisPool.getFinal(isCluster(), getHost(), getPort(), getPassword());
} }
@Override @Override
@ -151,6 +159,7 @@ public class RedisDatabaseConnection extends BaseConnection {
if (StringKit.isNotEmpty(pwd)) { if (StringKit.isNotEmpty(pwd)) {
setPassword(SecurityKit.encrypt(pwd)); setPassword(SecurityKit.encrypt(pwd));
} }
setCluster(reader.getAttrAsBoolean("cluster", false));
} }
} }
} }
@ -164,15 +173,17 @@ public class RedisDatabaseConnection extends BaseConnection {
if (StringKit.isNotEmpty(getPassword())) { if (StringKit.isNotEmpty(getPassword())) {
writer.attr("password", SecurityKit.decrypt(getPassword())); writer.attr("password", SecurityKit.decrypt(getPassword()));
} }
writer.attr("cluster", isCluster());
writer.end(); writer.end();
} }
@Override @Override
public Object clone() throws CloneNotSupportedException { 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<String>) host.clone(); cloned.host = (Conf<String>) host.clone();
cloned.port = (Conf<String>) port.clone(); cloned.port = (Conf<String>) port.clone();
cloned.password = (Conf<String>) password.clone(); cloned.password = (Conf<String>) password.clone();
cloned.cluster = (Conf<Boolean>) cluster.clone();
return cloned; return cloned;
} }
} }

6
src/main/java/com/fr/plugin/db/redis/core/RedisPool.java

@ -61,9 +61,11 @@ public class RedisPool {
jedisPoolMap.clear(); 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<Pair<String, Integer>> pairs = findAllHostAndPassword(host, port); List<Pair<String, Integer>> 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); return pool.getStandaloneResource(pairs.get(0), password);
} else { } else {
return pool.getJedisCluster(pairs, password); return pool.getJedisCluster(pairs, password);

1
src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java

@ -34,7 +34,6 @@ public class RedisTableDataModel extends BaseDataModel {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redis.getClient(), query, rowCount); DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redis.getClient(), query, rowCount);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start); LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
wrapper.transform(script);
data = wrapper.getData(); data = wrapper.getData();
columnNames = wrapper.getColumnNames(); columnNames = wrapper.getColumnNames();
} catch (Exception e) { } catch (Exception e) {

12
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.DesignKit;
import com.fanruan.api.design.ui.component.UIActionLabel; import com.fanruan.api.design.ui.component.UIActionLabel;
import com.fanruan.api.design.ui.component.UIButton; 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.UILabel;
import com.fanruan.api.design.ui.component.UIPasswordField; import com.fanruan.api.design.ui.component.UIPasswordField;
import com.fanruan.api.design.ui.component.UITextField; import com.fanruan.api.design.ui.component.UITextField;
@ -31,6 +32,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
private UITextField hostTextField; private UITextField hostTextField;
private UITextField portNumberField; private UITextField portNumberField;
private UIPasswordField passwordTextField; private UIPasswordField passwordTextField;
private UICheckBox clusterModeCheckBox;
@Override @Override
@ -40,7 +42,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
hostTextField = new UITextField(); hostTextField = new UITextField();
portNumberField = new UITextField(); portNumberField = new UITextField();
passwordTextField = new UIPasswordField(); passwordTextField = new UIPasswordField();
clusterModeCheckBox = new UICheckBox(DesignKit.i18nText("Plugin-Redis_Cluster_Mode"), false);
JPanel globalConfigPane = new JPanel(); JPanel globalConfigPane = new JPanel();
GridLayout gridLayout = new GridLayout(1, 2); GridLayout gridLayout = new GridLayout(1, 2);
@ -63,7 +65,11 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
Component[][] components = new Component[][]{ Component[][] components = new Component[][]{
{new UILabel(DesignKit.i18nText("Plugin-Redis_Host") + ":"), {new UILabel(DesignKit.i18nText("Plugin-Redis_Host") + ":"),
GUICoreKit.createBorderLayoutPane(hostTextField, BorderLayout.CENTER, helpButton, BorderLayout.EAST)}, GUICoreKit.createBorderLayoutPane(hostTextField, BorderLayout.CENTER,
GUICoreKit.createBorderLayoutPane(
clusterModeCheckBox, BorderLayout.CENTER,
helpButton, BorderLayout.EAST
), BorderLayout.EAST)},
{new UILabel(DesignKit.i18nText("Plugin-Redis_Port") + ":"), portNumberField}, {new UILabel(DesignKit.i18nText("Plugin-Redis_Port") + ":"), portNumberField},
{new UILabel(DesignKit.i18nText("Plugin-Redis_Password") + ":"), passwordTextField}, {new UILabel(DesignKit.i18nText("Plugin-Redis_Password") + ":"), passwordTextField},
{null, globalConfigPane} {null, globalConfigPane}
@ -135,6 +141,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
hostTextField.setText(ob.getHost()); hostTextField.setText(ob.getHost());
portNumberField.setText(ob.getPort()); portNumberField.setText(ob.getPort());
passwordTextField.setText(ob.getPassword()); passwordTextField.setText(ob.getPassword());
clusterModeCheckBox.setSelected(ob.isCluster());
} }
@Override @Override
@ -143,6 +150,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
connection.setHost(hostTextField.getText()); connection.setHost(hostTextField.getText());
connection.setPort(portNumberField.getText()); connection.setPort(portNumberField.getText());
connection.setPassword(passwordTextField.getText()); connection.setPassword(passwordTextField.getText());
connection.setCluster(clusterModeCheckBox.isSelected());
return connection; return connection;
} }

1
src/main/resources/com/fr/plugin/db/redis/locale/redis.properties

@ -39,3 +39,4 @@ Plugin-Redis_Cluster_Config_Description=Input multiple hosts with commas separat
Plugin-Redis_Script_Engine_Type=Script Engine Type Plugin-Redis_Script_Engine_Type=Script Engine Type
Plugin-Redis_Script_Engine_Type_Default=Default Plugin-Redis_Script_Engine_Type_Default=Default
Plugin-Redis_Script_Engine_Type_V8=V8 Plugin-Redis_Script_Engine_Type_V8=V8
Plugin-Redis_Cluster_Mode=Cluster Mode

1
src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties

@ -39,6 +39,7 @@ Plugin-Redis_Cluster_Config_Description=Input multiple hosts with commas separat
Plugin-Redis_Script_Engine_Type=Script Engine Type Plugin-Redis_Script_Engine_Type=Script Engine Type
Plugin-Redis_Script_Engine_Type_Default=Default Plugin-Redis_Script_Engine_Type_Default=Default
Plugin-Redis_Script_Engine_Type_V8=V8 Plugin-Redis_Script_Engine_Type_V8=V8
Plugin-Redis_Cluster_Mode=Cluster Mode
Plugin-Redis_Index=Index Plugin-Redis_Index=Index
Plugin-Redis_Set_Parameter=Parameter Plugin-Redis_Set_Parameter=Parameter
Plugin-Redis_Set_Parameter_Name=Parameter Name Plugin-Redis_Set_Parameter_Name=Parameter Name

11
src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties

@ -39,6 +39,7 @@ Plugin-Redis_Cluster_Config_Description=1\u3001\u4F7F\u7528\u9017\u53F7\u5206\u5
Plugin-Redis_Script_Engine_Type=\u811A\u672C\u5F15\u64CE Plugin-Redis_Script_Engine_Type=\u811A\u672C\u5F15\u64CE
Plugin-Redis_Script_Engine_Type_Default=\u9ED8\u8BA4 Plugin-Redis_Script_Engine_Type_Default=\u9ED8\u8BA4
Plugin-Redis_Script_Engine_Type_V8=V8\u9AD8\u901F\u5F15\u64CE Plugin-Redis_Script_Engine_Type_V8=V8\u9AD8\u901F\u5F15\u64CE
Plugin-Redis_Cluster_Mode=\u96C6\u7FA4\u6A21\u5F0F
Plugin-Redis_Proxy_Private_Key_Path_Mark=\u8BF7\u8F93\u5165\u670D\u52A1\u5668\u6587\u4EF6\u8DEF\u5F84 Plugin-Redis_Proxy_Private_Key_Path_Mark=\u8BF7\u8F93\u5165\u670D\u52A1\u5668\u6587\u4EF6\u8DEF\u5F84
Plugin-Redis_Connection_Form_OriginalCharsetName= \u7F16\u7801 Plugin-Redis_Connection_Form_OriginalCharsetName= \u7F16\u7801
Plugin-Redis_Check_Integer=\u8BF7\u8F93\u5165\u4E0D\u5C0F\u4E8E0\u7684\u6574\u6570 Plugin-Redis_Check_Integer=\u8BF7\u8F93\u5165\u4E0D\u5C0F\u4E8E0\u7684\u6574\u6570
@ -60,8 +61,8 @@ Plugin-Redis_Parameter_Delete_Confirm=\u4F60\u786E\u5B9A\u51B3\u5B9A\u5220\u9664
Plugin-Redis_Parameter_Delete_Alert=\u5F53\u524D\u5217\u8868\u4E3A\u7A7A\u6216\u8005\u4F60\u6CA1\u6709\u9009\u4E2D\u4EFB\u4F55\u9879 Plugin-Redis_Parameter_Delete_Alert=\u5F53\u524D\u5217\u8868\u4E3A\u7A7A\u6216\u8005\u4F60\u6CA1\u6709\u9009\u4E2D\u4EFB\u4F55\u9879
Plugin-Redis_View=\u89C6\u56FE Plugin-Redis_View=\u89C6\u56FE
Plugin-Redis_Table=\u8868 Plugin-Redis_Table=\u8868
Plugin-Redis_Index=\u7f16\u53f7 Plugin-Redis_Index=\u7F16\u53F7
Plugin-Redis_Set_Parameter=\u53c2\u6570 Plugin-Redis_Set_Parameter=\u53C2\u6570
Plugin-Redis_Set_Parameter_Name=\u53c2\u6570\u540d Plugin-Redis_Set_Parameter_Name=\u53C2\u6570\u540D
Plugin-Redis_Set_Parameter_Type=\u53c2\u6570\u7c7b\u578b Plugin-Redis_Set_Parameter_Type=\u53C2\u6570\u7C7B\u578B
Plugin-Redis_Set_Parameter_Value=\u53c2\u6570\u503c Plugin-Redis_Set_Parameter_Value=\u53C2\u6570\u503C
Loading…
Cancel
Save