From b342e3d90d8bf60dce57bd2fcd7ec5c409ed08a2 Mon Sep 17 00:00:00 2001 From: richie Date: Thu, 15 Nov 2018 15:18:26 +0800 Subject: [PATCH] =?UTF-8?q?redis=E6=95=B0=E6=8D=AE=E9=9B=86=E9=80=82?= =?UTF-8?q?=E9=85=8D10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../redis/core/RedisDatabaseConnection.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 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 1ea1213..bbf4ce4 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 @@ -1,15 +1,16 @@ package com.fr.plugin.db.redis.core; +import com.fr.config.holder.Conf; +import com.fr.config.holder.factory.Holders; import com.fr.data.impl.AbstractDatabaseConnection; import com.fr.data.impl.Connection; import com.fr.general.Inter; -import com.fr.stable.CodeUtils; +import com.fr.security.SecurityToolbox; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLableReader; import redis.clients.jedis.Jedis; -import redis.clients.jedis.exceptions.JedisConnectionException; import java.util.List; @@ -17,37 +18,36 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection { private static final int DEFAULT_REDIS_PORT = 6379; - - private String host; - private int port = DEFAULT_REDIS_PORT; - private String password; + private Conf host = Holders.simple(StringUtils.EMPTY); + private Conf port = Holders.simple(DEFAULT_REDIS_PORT); + private Conf password = Holders.simple(StringUtils.EMPTY); public RedisDatabaseConnection() { } public String getHost() { - return host; + return host.get(); } public void setHost(String host) { - this.host = host; + this.host.set(host); } public int getPort() { - return port; + return port.get(); } public void setPort(int port) { - this.port = port; + this.port.set(port); } public String getPassword() { - return password; + return password.get(); } public void setPassword(String password) { - this.password = password; + this.password.set(password); } @@ -66,9 +66,9 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection { } public Jedis createRedisClient() { - Jedis client = new Jedis(host, port); - if (StringUtils.isNotEmpty(password)) { - client.auth(password); + Jedis client = new Jedis(getHost(), getPort()); + if (StringUtils.isNotEmpty(getPassword())) { + client.auth(getPassword()); } return client; } @@ -128,11 +128,11 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection { if (reader.isChildNode()) { String tagName = reader.getTagName(); if ("Attr".equals(tagName)) { - host = reader.getAttrAsString("host", StringUtils.EMPTY); - port = reader.getAttrAsInt("port", DEFAULT_REDIS_PORT); + setHost(reader.getAttrAsString("host", StringUtils.EMPTY)); + setPort(reader.getAttrAsInt("port", DEFAULT_REDIS_PORT)); String pwd = reader.getAttrAsString("password", StringUtils.EMPTY); if (StringUtils.isNotEmpty(pwd)) { - password = CodeUtils.passwordDecode(pwd); + setPassword(SecurityToolbox.encrypt(pwd)); } } } @@ -142,10 +142,10 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection { public void writeXML(XMLPrintWriter writer) { super.writeXML(writer); writer.startTAG("Attr"); - writer.attr("host", host); - writer.attr("port", port); - if (StringUtils.isNotEmpty(password)) { - writer.attr("password", CodeUtils.passwordEncode(password)); + writer.attr("host", getHost()); + writer.attr("port", getPort()); + if (StringUtils.isNotEmpty(getPassword())) { + writer.attr("password", SecurityToolbox.decrypt(getPassword())); } writer.end(); } @@ -153,9 +153,9 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection { @Override public Object clone() throws CloneNotSupportedException { com.fr.plugin.db.redis.core.RedisDatabaseConnection cloned = (com.fr.plugin.db.redis.core.RedisDatabaseConnection) super.clone(); - cloned.host = host; - cloned.port = port; - cloned.password = password; + cloned.host = (Conf) host.clone(); + cloned.port = (Conf) port.clone(); + cloned.password = (Conf) password.clone(); return cloned; } } \ No newline at end of file