22
22
import java .util .List ;
23
23
24
24
import io .lettuce .core .RedisClient ;
25
- import io .lettuce .core .cluster .RedisClusterClient ;
26
25
import io .lettuce .core .resource .ClientResources ;
27
26
import io .lettuce .core .resource .DefaultClientResources ;
28
- import org .apache .commons .pool2 .impl .GenericObjectPool ;
29
27
import org .apache .commons .pool2 .impl .GenericObjectPoolConfig ;
30
28
31
29
import org .springframework .beans .factory .ObjectProvider ;
50
48
* @author Andy Wilkinson
51
49
*/
52
50
@ Configuration
53
- @ ConditionalOnClass ({ GenericObjectPool .class , RedisClient .class ,
54
- RedisClusterClient .class })
51
+ @ ConditionalOnClass (RedisClient .class )
55
52
class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
56
53
57
54
private final RedisProperties properties ;
@@ -84,15 +81,6 @@ public LettuceConnectionFactory redisConnectionFactory(
84
81
return createLettuceConnectionFactory (clientConfig );
85
82
}
86
83
87
- private static GenericObjectPoolConfig lettucePoolConfig (RedisProperties .Pool props ) {
88
- GenericObjectPoolConfig config = new GenericObjectPoolConfig ();
89
- config .setMaxTotal (props .getMaxActive ());
90
- config .setMaxIdle (props .getMaxIdle ());
91
- config .setMinIdle (props .getMinIdle ());
92
- config .setMaxWaitMillis (props .getMaxWait ());
93
- return config ;
94
- }
95
-
96
84
private LettuceConnectionFactory createLettuceConnectionFactory (
97
85
LettuceClientConfiguration clientConfiguration ) {
98
86
if (getSentinelConfig () != null ) {
@@ -107,14 +95,7 @@ private LettuceConnectionFactory createLettuceConnectionFactory(
107
95
108
96
private LettuceClientConfiguration getLettuceClientConfiguration (
109
97
ClientResources clientResources , Pool pool ) {
110
- LettuceClientConfigurationBuilder builder ;
111
- if (pool != null ) {
112
- builder = LettucePoolingClientConfiguration .builder ()
113
- .poolConfig (lettucePoolConfig (pool ));
114
- }
115
- else {
116
- builder = LettuceClientConfiguration .builder ();
117
- }
98
+ LettuceClientConfigurationBuilder builder = createBuilder (pool );
118
99
applyProperties (builder );
119
100
if (StringUtils .hasText (this .properties .getUrl ())) {
120
101
customizeConfigurationFromUrl (builder );
@@ -124,6 +105,13 @@ private LettuceClientConfiguration getLettuceClientConfiguration(
124
105
return builder .build ();
125
106
}
126
107
108
+ private LettuceClientConfigurationBuilder createBuilder (Pool pool ) {
109
+ if (pool == null ) {
110
+ return LettuceClientConfiguration .builder ();
111
+ }
112
+ return new PoolBuilderFactory ().createBuilder (pool );
113
+ }
114
+
127
115
private LettuceClientConfigurationBuilder applyProperties (
128
116
LettuceClientConfiguration .LettuceClientConfigurationBuilder builder ) {
129
117
if (this .properties .isSsl ()) {
@@ -157,4 +145,25 @@ private void customize(
157
145
}
158
146
}
159
147
148
+ /**
149
+ * Inner class to allow optional commons-pool2 dependency.
150
+ */
151
+ private static class PoolBuilderFactory {
152
+
153
+ public LettuceClientConfigurationBuilder createBuilder (Pool properties ) {
154
+ return LettucePoolingClientConfiguration .builder ()
155
+ .poolConfig (getPoolConfig (properties ));
156
+ }
157
+
158
+ private GenericObjectPoolConfig getPoolConfig (Pool properties ) {
159
+ GenericObjectPoolConfig config = new GenericObjectPoolConfig ();
160
+ config .setMaxTotal (properties .getMaxActive ());
161
+ config .setMaxIdle (properties .getMaxIdle ());
162
+ config .setMinIdle (properties .getMinIdle ());
163
+ config .setMaxWaitMillis (properties .getMaxWait ());
164
+ return config ;
165
+ }
166
+
167
+ }
168
+
160
169
}
0 commit comments