Skip to content

Added SSL support to LettuceConnectionFactory #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
* a {@link Pool} to pool dedicated connections. If shareNativeConnection is true, the pool will be used to select a
* connection for blocking and tx operations only, which should not share a connection. If native connection sharing is
* disabled, the selected connection will be used for all operations.
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
Expand Down Expand Up @@ -97,6 +97,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
private RedisClusterConfiguration clusterConfiguration;
private ClusterCommandExecutor clusterCommandExecutor;
private ClientResources clientResources;
private boolean useSsl;

/**
* Constructs a new <code>LettuceConnectionFactory</code> instance with default settings.
Expand Down Expand Up @@ -124,7 +125,7 @@ public LettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration
/**
* Constructs a new {@link LettuceConnectionFactory} instance using the given {@link RedisClusterConfiguration}
* applied to create a {@link RedisClusterClient}.
*
*
* @param clusterConfig
* @since 1.7
*/
Expand Down Expand Up @@ -256,7 +257,7 @@ public DataAccessException translateExceptionIfPossible(RuntimeException ex) {

/**
* Returns the current host.
*
*
* @return the host
*/
public String getHostName() {
Expand All @@ -265,7 +266,7 @@ public String getHostName() {

/**
* Sets the host.
*
*
* @param host the host to set
*/
public void setHostName(String host) {
Expand All @@ -274,7 +275,7 @@ public void setHostName(String host) {

/**
* Returns the current port.
*
*
* @return the port
*/
public int getPort() {
Expand All @@ -283,7 +284,7 @@ public int getPort() {

/**
* Sets the port.
*
*
* @param port the port to set
*/
public void setPort(int port) {
Expand All @@ -292,7 +293,7 @@ public void setPort(int port) {

/**
* Returns the connection timeout (in milliseconds).
*
*
* @return connection timeout
*/
public long getTimeout() {
Expand All @@ -301,16 +302,23 @@ public long getTimeout() {

/**
* Sets the connection timeout (in milliseconds).
*
*
* @param timeout connection timeout
*/
public void setTimeout(long timeout) {
this.timeout = timeout;
}

/**
* Sets to use SSL connection
*/
public void setUseSsl(boolean useSsl){
this.useSsl = useSsl;
}

/**
* Indicates if validation of the native Lettuce connection is enabled
*
*
* @return connection validation enabled
*/
public boolean getValidateConnection() {
Expand All @@ -327,7 +335,7 @@ public boolean getValidateConnection() {
* Setting this to true will result in a round-trip call to the server on each new connection, so this setting should
* only be used if connection sharing is enabled and there is code that is actively closing the native Lettuce
* connection.
*
*
* @param validateConnection enable connection validation
*/
public void setValidateConnection(boolean validateConnection) {
Expand All @@ -336,7 +344,7 @@ public void setValidateConnection(boolean validateConnection) {

/**
* Indicates if multiple {@link LettuceConnection}s should share a single native connection.
*
*
* @return native connection shared
*/
public boolean getShareNativeConnection() {
Expand All @@ -346,7 +354,7 @@ public boolean getShareNativeConnection() {
/**
* Enables multiple {@link LettuceConnection}s to share a single native connection. If set to false, every operation
* on {@link LettuceConnection} will open and close a socket.
*
*
* @param shareNativeConnection enable connection sharing
*/
public void setShareNativeConnection(boolean shareNativeConnection) {
Expand All @@ -355,7 +363,7 @@ public void setShareNativeConnection(boolean shareNativeConnection) {

/**
* Returns the index of the database.
*
*
* @return Returns the database index
*/
public int getDatabase() {
Expand All @@ -364,7 +372,7 @@ public int getDatabase() {

/**
* Sets the index of the database used by this connection factory. Default is 0.
*
*
* @param index database index
*/
public void setDatabase(int index) {
Expand All @@ -374,7 +382,7 @@ public void setDatabase(int index) {

/**
* Returns the password used for authenticating with the Redis server.
*
*
* @return password for authentication
*/
public String getPassword() {
Expand All @@ -383,7 +391,7 @@ public String getPassword() {

/**
* Sets the password used for authenticating with the Redis server.
*
*
* @param password the password to set
*/
public void setPassword(String password) {
Expand All @@ -392,7 +400,7 @@ public void setPassword(String password) {

/**
* Returns the shutdown timeout for shutting down the RedisClient (in milliseconds).
*
*
* @return shutdown timeout
* @since 1.6
*/
Expand All @@ -402,7 +410,7 @@ public long getShutdownTimeout() {

/**
* Sets the shutdown timeout for shutting down the RedisClient (in milliseconds).
*
*
* @param shutdownTimeout the shutdown timeout
* @since 1.6
*/
Expand All @@ -412,7 +420,7 @@ public void setShutdownTimeout(long shutdownTimeout) {

/**
* Get the {@link ClientResources} to reuse infrastructure.
*
*
* @return {@literal null} if not set.
* @since 1.7
*/
Expand All @@ -423,7 +431,7 @@ public ClientResources getClientResources() {
/**
* Sets the {@link ClientResources} to reuse the client infrastructure. <br />
* Set to {@literal null} to not share resources.
*
*
* @param clientResources can be {@literal null}.
* @since 1.7
*/
Expand All @@ -435,7 +443,7 @@ public void setClientResources(ClientResources clientResources) {
* Specifies if pipelined results should be converted to the expected data type. If false, results of
* {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()} will be of the type returned by the
* Lettuce driver
*
*
* @return Whether or not to convert pipeline and tx results
*/
public boolean getConvertPipelineAndTxResults() {
Expand All @@ -446,7 +454,7 @@ public boolean getConvertPipelineAndTxResults() {
* Specifies if pipelined and transaction results should be converted to the expected data type. If false, results of
* {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()} will be of the type returned by the
* Lettuce driver
*
*
* @param convertPipelineAndTxResults Whether or not to convert pipeline and tx results
*/
public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) {
Expand Down Expand Up @@ -536,6 +544,7 @@ private AbstractRedisClient createRedisClient() {
if (password != null) {
builder.withPassword(password);
}
builder.withSsl(useSsl);
builder.withTimeout(timeout, TimeUnit.MILLISECONDS);
if (clientResources != null) {
return RedisClient.create(clientResources, builder.build());
Expand Down