pingConnection, keepAlive, tcpNoDelay settings were added. #1088

pull/1105/head
Nikita 7 years ago
parent a22deac08b
commit 903215d6d1

@ -94,6 +94,8 @@ public class RedisClient {
bootstrap.handler(new RedisChannelInitializer(bootstrap, config, this, channels, type));
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout());
bootstrap.option(ChannelOption.SO_KEEPALIVE, config.isKeepAlive());
bootstrap.option(ChannelOption.TCP_NODELAY, config.isTcpNoDelay());
return bootstrap;
}

@ -49,6 +49,9 @@ public class RedisClientConfig {
private String clientName;
private boolean readOnly;
private boolean keepPubSubOrder = true;
private boolean pingConnection;
private boolean keepAlive;
private boolean tcpNoDelay;
private boolean sslEnableEndpointIdentification = true;
private SslProvider sslProvider = SslProvider.JDK;
@ -206,8 +209,33 @@ public class RedisClientConfig {
public boolean isKeepPubSubOrder() {
return keepPubSubOrder;
}
public void setKeepPubSubOrder(boolean keepPubSubOrder) {
public RedisClientConfig setKeepPubSubOrder(boolean keepPubSubOrder) {
this.keepPubSubOrder = keepPubSubOrder;
return this;
}
public boolean isPingConnection() {
return pingConnection;
}
public RedisClientConfig setPingConnection(boolean pingConnection) {
this.pingConnection = pingConnection;
return this;
}
public boolean isKeepAlive() {
return keepAlive;
}
public RedisClientConfig setKeepAlive(boolean keepAlive) {
this.keepAlive = keepAlive;
return this;
}
public boolean isTcpNoDelay() {
return tcpNoDelay;
}
public RedisClientConfig setTcpNoDelay(boolean tcpNoDelay) {
this.tcpNoDelay = tcpNoDelay;
return this;
}
}

@ -80,6 +80,10 @@ public abstract class BaseConnectionHandler<C extends RedisConnection> extends C
RFuture<Object> future = connection.async(RedisCommands.READONLY);
futures.add(future);
}
if (config.isPingConnection()) {
RFuture<Object> future = connection.async(RedisCommands.PING);
futures.add(future);
}
if (futures.isEmpty()) {
ctx.fireChannelActive();

@ -105,6 +105,12 @@ class BaseConfig<T extends BaseConfig<T>> {
private String sslKeystorePassword;
private boolean pingConnection;
private boolean keepAlive;
private boolean tcpNoDelay;
BaseConfig() {
}
@ -127,6 +133,9 @@ class BaseConfig<T extends BaseConfig<T>> {
setSslTruststorePassword(config.getSslTruststorePassword());
setSslKeystore(config.getSslKeystore());
setSslKeystorePassword(config.getSslKeystorePassword());
setPingConnection(config.isPingConnection());
setKeepAlive(config.isKeepAlive());
setTcpNoDelay(config.isTcpNoDelay());
}
/**
@ -332,7 +341,7 @@ class BaseConfig<T extends BaseConfig<T>> {
/**
* Enables SSL endpoint identification.
* <p>
* Default is true
* Default is <code>true</code>
*
* @param sslEnableEndpointIdentification - boolean value
* @return config
@ -419,6 +428,57 @@ class BaseConfig<T extends BaseConfig<T>> {
return (T) this;
}
public boolean isPingConnection() {
return pingConnection;
}
/**
* Enables PING command sending during connection initialization
* <p>
* Default is <code>false</code>
*
* @param pingConnection - boolean value
* @return config
*/
public T setPingConnection(boolean pingConnection) {
this.pingConnection = pingConnection;
return (T) this;
}
public boolean isKeepAlive() {
return keepAlive;
}
/**
* Enables TCP keepAlive for connection
* <p>
* Default is <code>false</code>
*
* @param keepAlive - boolean value
* @return config
*/
public T setKeepAlive(boolean keepAlive) {
this.keepAlive = keepAlive;
return (T) this;
}
public boolean isTcpNoDelay() {
return tcpNoDelay;
}
/**
* Enables TCP noDelay for connection
* <p>
* Default is <code>false</code>
*
* @param tcpNoDelay - boolean value
* @return config
*/
public T setTcpNoDelay(boolean tcpNoDelay) {
this.tcpNoDelay = tcpNoDelay;
return (T) this;
}
}

@ -377,7 +377,10 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
.setSslKeystore(config.getSslKeystore())
.setSslKeystorePassword(config.getSslKeystorePassword())
.setClientName(config.getClientName())
.setKeepPubSubOrder(cfg.isKeepPubSubOrder());
.setKeepPubSubOrder(cfg.isKeepPubSubOrder())
.setPingConnection(config.isPingConnection())
.setKeepAlive(config.isKeepAlive())
.setTcpNoDelay(config.isTcpNoDelay());
if (type != NodeType.SENTINEL) {
redisConfig.setDatabase(config.getDatabase());

Loading…
Cancel
Save