44
55import org .apache .commons .pool2 .impl .GenericObjectPool ;
66import org .apache .commons .pool2 .impl .GenericObjectPoolConfig ;
7- import org .springframework .beans .factory .annotation .Autowired ;
87import org .springframework .boot .autoconfigure .data .redis .RedisProperties ;
98import org .springframework .boot .autoconfigure .data .redis .RedisProperties .Pool ;
10- import org .springframework .boot .context .properties .ConfigurationProperties ;
119import org .springframework .boot .context .properties .EnableConfigurationProperties ;
1210import org .springframework .context .annotation .Bean ;
1311import org .springframework .context .annotation .Configuration ;
1917import io .lettuce .core .resource .ClientResources ;
2018import io .lettuce .core .resource .DefaultClientResources ;
2119import io .lettuce .core .support .ConnectionPoolSupport ;
22- import lombok .AccessLevel ;
23- import lombok .Data ;
24- import lombok .Getter ;
25- import lombok .Setter ;
2620
2721@ Configuration (proxyBeanMethods = false )
28- @ ConfigurationProperties (prefix = "spring.redisearch" )
2922@ EnableConfigurationProperties (RedisProperties .class )
30- public @ Data class RediSearchAutoConfiguration {
31-
32- @ Autowired
33- @ Getter (AccessLevel .NONE )
34- @ Setter (AccessLevel .NONE )
35- private RedisProperties props ;
36- private String host ;
37- private Integer port ;
38- private String password ;
39- private Duration timeout ;
40- private Pool pool ;
23+ public class RediSearchAutoConfiguration {
4124
4225 @ Bean (destroyMethod = "shutdown" )
4326 ClientResources clientResources () {
4427 return DefaultClientResources .create ();
4528 }
4629
4730 @ Bean (destroyMethod = "shutdown" )
48- RediSearchClient client (ClientResources clientResources ) {
49- RedisURI redisURI = RedisURI .create (host (), port ());
50- String password = password ();
51- if (password != null ) {
52- redisURI .setPassword (password );
31+ RediSearchClient client (RedisProperties props , ClientResources clientResources ) {
32+ RedisURI redisURI = RedisURI .create (props .getHost (), props .getPort ());
33+ if (props .getPassword () != null ) {
34+ redisURI .setPassword (props .getPassword ());
5335 }
54- Duration timeout = timeout ();
36+ Duration timeout = props . getTimeout ();
5537 if (timeout != null ) {
5638 redisURI .setTimeout (timeout );
5739 }
@@ -64,13 +46,13 @@ StatefulRediSearchConnection<String, String> connection(RediSearchClient rediSea
6446 }
6547
6648 @ Bean (name = "rediSearchConnectionPool" , destroyMethod = "close" )
67- GenericObjectPool <StatefulRediSearchConnection <String , String >> rediSearchConnectionPool (
49+ GenericObjectPool <StatefulRediSearchConnection <String , String >> pool ( RedisProperties props ,
6850 RediSearchClient rediSearchClient ) {
6951 GenericObjectPoolConfig <StatefulRediSearchConnection <String , String >> config = new GenericObjectPoolConfig <StatefulRediSearchConnection <String , String >>();
7052 config .setJmxEnabled (false );
7153 GenericObjectPool <StatefulRediSearchConnection <String , String >> pool = ConnectionPoolSupport
7254 .createGenericObjectPool (() -> rediSearchClient .connect (), config );
73- Pool poolProps = pool ();
55+ Pool poolProps = props . getLettuce (). getPool ();
7456 if (poolProps != null ) {
7557 pool .setMaxTotal (poolProps .getMaxActive ());
7658 pool .setMaxIdle (poolProps .getMaxIdle ());
@@ -82,38 +64,4 @@ GenericObjectPool<StatefulRediSearchConnection<String, String>> rediSearchConnec
8264 return pool ;
8365 }
8466
85- private Pool pool () {
86- if (pool == null ) {
87- return props .getLettuce ().getPool ();
88- }
89- return pool ;
90- }
91-
92- private String host () {
93- if (host == null ) {
94- return props .getHost ();
95- }
96- return host ;
97- }
98-
99- private int port () {
100- if (port == null ) {
101- return props .getPort ();
102- }
103- return port ;
104- }
105-
106- private String password () {
107- if (password == null ) {
108- return props .getPassword ();
109- }
110- return password ;
111- }
112-
113- private Duration timeout () {
114- if (timeout == null ) {
115- return props .getTimeout ();
116- }
117- return timeout ;
118- }
11967}
0 commit comments