Browse Source

redis数据集适配10.0

paid
richie 6 years ago
parent
commit
b342e3d90d
  1. 50
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java

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

@ -1,15 +1,16 @@
package com.fr.plugin.db.redis.core; 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.AbstractDatabaseConnection;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.stable.CodeUtils; import com.fr.security.SecurityToolbox;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisConnectionException;
import java.util.List; import java.util.List;
@ -17,37 +18,36 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
private static final int DEFAULT_REDIS_PORT = 6379; private static final int DEFAULT_REDIS_PORT = 6379;
private Conf<String> host = Holders.simple(StringUtils.EMPTY);
private String host; private Conf<Integer> port = Holders.simple(DEFAULT_REDIS_PORT);
private int port = DEFAULT_REDIS_PORT; private Conf<String> password = Holders.simple(StringUtils.EMPTY);
private String password;
public RedisDatabaseConnection() { public RedisDatabaseConnection() {
} }
public String getHost() { public String getHost() {
return host; return host.get();
} }
public void setHost(String host) { public void setHost(String host) {
this.host = host; this.host.set(host);
} }
public int getPort() { public int getPort() {
return port; return port.get();
} }
public void setPort(int port) { public void setPort(int port) {
this.port = port; this.port.set(port);
} }
public String getPassword() { public String getPassword() {
return password; return password.get();
} }
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password.set(password);
} }
@ -66,9 +66,9 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
} }
public Jedis createRedisClient() { public Jedis createRedisClient() {
Jedis client = new Jedis(host, port); Jedis client = new Jedis(getHost(), getPort());
if (StringUtils.isNotEmpty(password)) { if (StringUtils.isNotEmpty(getPassword())) {
client.auth(password); client.auth(getPassword());
} }
return client; return client;
} }
@ -128,11 +128,11 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
if (reader.isChildNode()) { if (reader.isChildNode()) {
String tagName = reader.getTagName(); String tagName = reader.getTagName();
if ("Attr".equals(tagName)) { if ("Attr".equals(tagName)) {
host = reader.getAttrAsString("host", StringUtils.EMPTY); setHost(reader.getAttrAsString("host", StringUtils.EMPTY));
port = reader.getAttrAsInt("port", DEFAULT_REDIS_PORT); setPort(reader.getAttrAsInt("port", DEFAULT_REDIS_PORT));
String pwd = reader.getAttrAsString("password", StringUtils.EMPTY); String pwd = reader.getAttrAsString("password", StringUtils.EMPTY);
if (StringUtils.isNotEmpty(pwd)) { 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) { public void writeXML(XMLPrintWriter writer) {
super.writeXML(writer); super.writeXML(writer);
writer.startTAG("Attr"); writer.startTAG("Attr");
writer.attr("host", host); writer.attr("host", getHost());
writer.attr("port", port); writer.attr("port", getPort());
if (StringUtils.isNotEmpty(password)) { if (StringUtils.isNotEmpty(getPassword())) {
writer.attr("password", CodeUtils.passwordEncode(password)); writer.attr("password", SecurityToolbox.decrypt(getPassword()));
} }
writer.end(); writer.end();
} }
@ -153,9 +153,9 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
@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 = (com.fr.plugin.db.redis.core.RedisDatabaseConnection) super.clone();
cloned.host = host; cloned.host = (Conf<String>) host.clone();
cloned.port = port; cloned.port = (Conf<Integer>) port.clone();
cloned.password = password; cloned.password = (Conf<String>) password.clone();
return cloned; return cloned;
} }
} }
Loading…
Cancel
Save