@ -17,9 +17,11 @@
package org.springframework.boot.autoconfigure.data.redis ;
package org.springframework.boot.autoconfigure.data.redis ;
import java.net.UnknownHostException ;
import java.net.UnknownHostException ;
import java.time.Duration ;
import io.lettuce.core.ClientOptions ;
import io.lettuce.core.ClientOptions ;
import io.lettuce.core.RedisClient ;
import io.lettuce.core.RedisClient ;
import io.lettuce.core.SocketOptions ;
import io.lettuce.core.TimeoutOptions ;
import io.lettuce.core.TimeoutOptions ;
import io.lettuce.core.cluster.ClusterClientOptions ;
import io.lettuce.core.cluster.ClusterClientOptions ;
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions ;
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions ;
@ -96,7 +98,7 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
if ( StringUtils . hasText ( getProperties ( ) . getUrl ( ) ) ) {
if ( StringUtils . hasText ( getProperties ( ) . getUrl ( ) ) ) {
customizeConfigurationFromUrl ( builder ) ;
customizeConfigurationFromUrl ( builder ) ;
}
}
builder . clientOptions ( initializeClientOptionsBuilder( ) . timeoutOptions ( TimeoutOptions . enabled ( ) ) . build ( ) ) ;
builder . clientOptions ( createClientOptions ( ) ) ;
builder . clientResources ( clientResources ) ;
builder . clientResources ( clientResources ) ;
builderCustomizers . orderedStream ( ) . forEach ( ( customizer ) - > customizer . customize ( builder ) ) ;
builderCustomizers . orderedStream ( ) . forEach ( ( customizer ) - > customizer . customize ( builder ) ) ;
return builder . build ( ) ;
return builder . build ( ) ;
@ -129,6 +131,15 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
return builder ;
return builder ;
}
}
private ClientOptions createClientOptions ( ) {
ClientOptions . Builder builder = initializeClientOptionsBuilder ( ) ;
Duration connectTimeout = getProperties ( ) . getConnectTimeout ( ) ;
if ( connectTimeout ! = null ) {
builder . socketOptions ( SocketOptions . builder ( ) . connectTimeout ( connectTimeout ) . build ( ) ) ;
}
return builder . timeoutOptions ( TimeoutOptions . enabled ( ) ) . build ( ) ;
}
private ClientOptions . Builder initializeClientOptionsBuilder ( ) {
private ClientOptions . Builder initializeClientOptionsBuilder ( ) {
if ( getProperties ( ) . getCluster ( ) ! = null ) {
if ( getProperties ( ) . getCluster ( ) ! = null ) {
ClusterClientOptions . Builder builder = ClusterClientOptions . builder ( ) ;
ClusterClientOptions . Builder builder = ClusterClientOptions . builder ( ) ;