Browse Source

redis数据集适配10.0

pull/12/head
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;
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<String> host = Holders.simple(StringUtils.EMPTY);
private Conf<Integer> port = Holders.simple(DEFAULT_REDIS_PORT);
private Conf<String> 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<String>) host.clone();
cloned.port = (Conf<Integer>) port.clone();
cloned.password = (Conf<String>) password.clone();
return cloned;
}
}
Loading…
Cancel
Save