Skip to content
This repository was archived by the owner on May 19, 2022. It is now read-only.

Commit fac1d96

Browse files
committed
added connection pool
1 parent e905d31 commit fac1d96

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@
5454
<groupId>io.lettuce</groupId>
5555
<artifactId>lettuce-core</artifactId>
5656
<version>5.2.0.BUILD-SNAPSHOT</version>
57-
</dependency>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.commons</groupId>
60+
<artifactId>commons-pool2</artifactId>
61+
</dependency>
5862
<dependency>
5963
<groupId>com.redislabs</groupId>
6064
<artifactId>lettusearch</artifactId>

src/main/java/com/redislabs/springredisearch/RediSearchConfiguration.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import java.time.Duration;
44

5+
import org.apache.commons.pool2.impl.GenericObjectPool;
6+
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
57
import org.springframework.beans.factory.annotation.Autowired;
68
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
9+
import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Pool;
710
import org.springframework.boot.context.properties.ConfigurationProperties;
811
import org.springframework.context.annotation.Bean;
912
import org.springframework.context.annotation.Configuration;
@@ -15,6 +18,7 @@
1518
import io.lettuce.core.RedisURI;
1619
import io.lettuce.core.resource.ClientResources;
1720
import io.lettuce.core.resource.DefaultClientResources;
21+
import io.lettuce.core.support.ConnectionPoolSupport;
1822
import lombok.AccessLevel;
1923
import lombok.Data;
2024
import lombok.Getter;
@@ -34,6 +38,7 @@ public class RediSearchConfiguration {
3438
private String password;
3539
private Duration timeout;
3640
private boolean publishOnScheduler;
41+
private int poolSize = 1;
3742

3843
@Bean(destroyMethod = "shutdown")
3944
ClientResources clientResources() {
@@ -61,6 +66,24 @@ StatefulRediSearchConnection<String, String> connection(RediSearchClient rediSea
6166
return rediSearchClient.connect();
6267
}
6368

69+
@Bean(name = "rediSearchConnectionPool", destroyMethod = "close")
70+
GenericObjectPool<StatefulRediSearchConnection<String, String>> rediSearchConnectionPool(
71+
RediSearchClient rediSearchClient) {
72+
GenericObjectPool<StatefulRediSearchConnection<String, String>> pool = ConnectionPoolSupport
73+
.createGenericObjectPool(() -> rediSearchClient.connect(),
74+
new GenericObjectPoolConfig<StatefulRediSearchConnection<String, String>>());
75+
if (props.getLettuce().getPool() != null) {
76+
Pool properties = props.getLettuce().getPool();
77+
pool.setMaxTotal(properties.getMaxActive());
78+
pool.setMaxIdle(properties.getMaxIdle());
79+
pool.setMinIdle(properties.getMinIdle());
80+
if (properties.getMaxWait() != null) {
81+
pool.setMaxWaitMillis(properties.getMaxWait().toMillis());
82+
}
83+
}
84+
return pool;
85+
}
86+
6487
private String host() {
6588
if (host == null) {
6689
return props.getHost();

0 commit comments

Comments
 (0)