Use Jedis rather than Lettuce as preferred Redis client
Salvatore has indicated that Jedis is his Java Redis client of choice. This commit updates the auto-configuration support, actuator and Redis starter accordingly. Completes #745
This commit is contained in:
@@ -48,11 +48,6 @@
|
||||
<artifactId>metrics-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lambdaworks</groupId>
|
||||
<artifactId>lettuce</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
@@ -108,6 +103,11 @@
|
||||
<artifactId>jolokia-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class RedisServer implements TestRule {
|
||||
|
||||
private static final String EXTERNAL_SERVERS_REQUIRED = "EXTERNAL_SERVERS_REQUIRED";
|
||||
|
||||
protected LettuceConnectionFactory resource;
|
||||
protected JedisConnectionFactory resource;
|
||||
|
||||
private final String resourceDescription = "Redis ConnectionFactory";
|
||||
|
||||
@@ -122,7 +122,7 @@ public class RedisServer implements TestRule {
|
||||
|
||||
/**
|
||||
* Perform cleanup of the {@link #resource} field, which is guaranteed to be non null.
|
||||
*
|
||||
*
|
||||
* @throws Exception any exception thrown by this method will be logged and swallowed
|
||||
*/
|
||||
protected void cleanupResource() throws Exception {
|
||||
@@ -134,8 +134,8 @@ public class RedisServer implements TestRule {
|
||||
* {@link #resource} field with a valid resource and return normally, or throw an
|
||||
* exception.
|
||||
*/
|
||||
protected LettuceConnectionFactory obtainResource() throws Exception {
|
||||
LettuceConnectionFactory resource = new LettuceConnectionFactory();
|
||||
protected JedisConnectionFactory obtainResource() throws Exception {
|
||||
JedisConnectionFactory resource = new JedisConnectionFactory();
|
||||
resource.afterPropertiesSet();
|
||||
resource.getConnection().close();
|
||||
return resource;
|
||||
|
||||
@@ -147,8 +147,8 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lambdaworks</groupId>
|
||||
<artifactId>lettuce</artifactId>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -27,25 +27,24 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClas
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.PoolConfig;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.DefaultLettucePool;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnection;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettucePool;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnection;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
import com.lambdaworks.redis.RedisClient;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Redis support.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ LettuceConnection.class, RedisOperations.class, RedisClient.class })
|
||||
@ConditionalOnClass({ JedisConnection.class, RedisOperations.class, Jedis.class })
|
||||
@EnableConfigurationProperties
|
||||
public class RedisAutoConfiguration {
|
||||
|
||||
@@ -59,8 +58,9 @@ public class RedisAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
RedisConnectionFactory redisConnectionFactory() throws UnknownHostException {
|
||||
LettuceConnectionFactory factory = new LettuceConnectionFactory(
|
||||
this.properties.getHost(), this.properties.getPort());
|
||||
JedisConnectionFactory factory = new JedisConnectionFactory();
|
||||
factory.setHostName(this.properties.getHost());
|
||||
factory.setPort(this.properties.getPort());
|
||||
if (this.properties.getPassword() != null) {
|
||||
factory.setPassword(this.properties.getPassword());
|
||||
}
|
||||
@@ -80,35 +80,27 @@ public class RedisAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
RedisConnectionFactory redisConnectionFactory() throws UnknownHostException {
|
||||
if (this.properties.getPool() != null) {
|
||||
LettuceConnectionFactory factory = new LettuceConnectionFactory(
|
||||
lettucePool());
|
||||
JedisConnectionFactory factory = new JedisConnectionFactory(
|
||||
jedisPoolConfig());
|
||||
return factory;
|
||||
}
|
||||
LettuceConnectionFactory factory = new LettuceConnectionFactory(
|
||||
this.properties.getHost(), this.properties.getPort());
|
||||
JedisConnectionFactory factory = new JedisConnectionFactory();
|
||||
factory.setHostName(this.properties.getHost());
|
||||
factory.setPort(this.properties.getPort());
|
||||
if (this.properties.getPassword() != null) {
|
||||
factory.setPassword(this.properties.getPassword());
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public LettucePool lettucePool() {
|
||||
return new DefaultLettucePool(this.properties.getHost(),
|
||||
this.properties.getPort(), poolConfig());
|
||||
}
|
||||
|
||||
private PoolConfig poolConfig() {
|
||||
PoolConfig pool = new PoolConfig();
|
||||
private JedisPoolConfig jedisPoolConfig() {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
RedisProperties.Pool props = this.properties.getPool();
|
||||
if (props != null) {
|
||||
pool.setMaxActive(props.getMaxActive());
|
||||
pool.setMaxIdle(props.getMaxIdle());
|
||||
pool.setMinIdle(props.getMinIdle());
|
||||
pool.setMaxWait(props.getMaxWait());
|
||||
}
|
||||
return pool;
|
||||
config.setMaxActive(props.getMaxActive());
|
||||
config.setMaxIdle(props.getMaxIdle());
|
||||
config.setMinIdle(props.getMinIdle());
|
||||
config.setMaxWait(props.getMaxWait());
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class RedisAutoConfigurationTests {
|
||||
this.context.register(RedisAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertEquals("foo", this.context.getBean(LettuceConnectionFactory.class)
|
||||
assertEquals("foo", this.context.getBean(JedisConnectionFactory.class)
|
||||
.getHostName());
|
||||
}
|
||||
|
||||
|
||||
@@ -65,12 +65,12 @@
|
||||
<hsqldb.version>2.3.2</hsqldb.version>
|
||||
<jackson.version>2.3.3</jackson.version>
|
||||
<javassist.version>3.18.1-GA</javassist.version> <!-- Same as Hibernate -->
|
||||
<jedis.version>2.1.0</jedis.version>
|
||||
<jetty.version>8.1.14.v20131031</jetty.version>
|
||||
<joda-time.version>2.3</joda-time.version>
|
||||
<jolokia.version>1.2.0</jolokia.version>
|
||||
<jstl.version>1.2</jstl.version>
|
||||
<junit.version>4.11</junit.version>
|
||||
<lettuce.version>2.3.3</lettuce.version>
|
||||
<liquibase.version>3.1.1</liquibase.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<logback.version>1.1.2</logback.version>
|
||||
@@ -155,9 +155,9 @@
|
||||
<version>${commons-pool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lambdaworks</groupId>
|
||||
<artifactId>lettuce</artifactId>
|
||||
<version>${lettuce.version}</version>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>${jedis.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lambdaworks</groupId>
|
||||
<artifactId>lettuce</artifactId>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user