DATAREDIS-506 - Upgrade to Jedis 2.9.0.
We now support Jedis 2.9.0 with Redis Standalone SSL and Redis Cluster with passwords. The code is compatible with Jedis 2.8.0 when not using SSL or Redis Cluster with passwords. Original Pull Request: #211
This commit is contained in:
committed by
Christoph Strobl
parent
34f2d95669
commit
1a332c0f57
1
Makefile
1
Makefile
@@ -57,6 +57,7 @@ work/sentinel-%.conf:
|
||||
|
||||
echo port $* >> $@
|
||||
echo daemonize yes >> $@
|
||||
echo bind 0.0.0.0 >> $@
|
||||
echo pidfile $(shell pwd)/work/sentinel-$*.pid >> $@
|
||||
echo logfile $(shell pwd)/work/sentinel-$*.log >> $@
|
||||
echo save \"\" >> $@
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -23,7 +23,7 @@
|
||||
<xstream>1.4.8</xstream>
|
||||
<pool>2.2</pool>
|
||||
<lettuce>3.4.2.Final</lettuce>
|
||||
<jedis>2.8.1</jedis>
|
||||
<jedis>2.9.0</jedis>
|
||||
<srp>0.7</srp>
|
||||
<jredis>06052013</jredis>
|
||||
<multithreadedtc>1.01</multithreadedtc>
|
||||
|
||||
@@ -770,7 +770,7 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
throw new InvalidDataAccessApiUsageException("No ongoing transaction. Did you forget to call multi?");
|
||||
}
|
||||
List<Object> results = transaction.exec();
|
||||
return convertPipelineAndTxResults
|
||||
return convertPipelineAndTxResults && results != null && !results.isEmpty()
|
||||
? new TransactionResultConverter<Response<?>>(txResults, JedisConverters.exceptionConverter())
|
||||
.convert(results)
|
||||
: results;
|
||||
|
||||
@@ -97,6 +97,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
private int timeout = Protocol.DEFAULT_TIMEOUT;
|
||||
private String password;
|
||||
private boolean usePool = true;
|
||||
private boolean useSsl = false;
|
||||
private Pool<Jedis> pool;
|
||||
private JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
private int dbIndex = 0;
|
||||
@@ -264,8 +265,12 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
* @since 1.4
|
||||
*/
|
||||
protected Pool<Jedis> createRedisPool() {
|
||||
return new JedisPool(getPoolConfig(), getShardInfo().getHost(), getShardInfo().getPort(),
|
||||
getTimeoutFrom(getShardInfo()), getShardInfo().getPassword());
|
||||
|
||||
return useSsl
|
||||
? new JedisPool(getPoolConfig(), getShardInfo().getHost(), getShardInfo().getPort(),
|
||||
getTimeoutFrom(getShardInfo()), getShardInfo().getPassword(), true)
|
||||
: new JedisPool(getPoolConfig(), getShardInfo().getHost(), getShardInfo().getPort(),
|
||||
getTimeoutFrom(getShardInfo()), getShardInfo().getPassword());
|
||||
}
|
||||
|
||||
private JedisCluster createCluster() {
|
||||
@@ -295,14 +300,15 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
|
||||
int redirects = clusterConfig.getMaxRedirects() != null ? clusterConfig.getMaxRedirects().intValue() : 5;
|
||||
|
||||
if (StringUtils.hasText(getPassword())) {
|
||||
throw new IllegalArgumentException("Jedis does not support password protected Redis Cluster configurations!");
|
||||
if (poolConfig != null) {
|
||||
return StringUtils.hasText(getPassword())
|
||||
? new JedisCluster(hostAndPort, timeout, timeout, redirects, getPassword(), poolConfig)
|
||||
: new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
|
||||
}
|
||||
|
||||
if (poolConfig != null) {
|
||||
return new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
|
||||
}
|
||||
return new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
|
||||
return StringUtils.hasText(getPassword())
|
||||
? new JedisCluster(hostAndPort, timeout, timeout, redirects, getPassword(), poolConfig)
|
||||
: new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -388,6 +394,26 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
this.hostName = hostName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to use SSL.
|
||||
*
|
||||
* @param useSsl {@literal true} to use SSL.
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setUseSsl(boolean useSsl) {
|
||||
this.useSsl = useSsl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to use SSL.
|
||||
*
|
||||
* @return use of SSL
|
||||
* @since 1.8
|
||||
*/
|
||||
public boolean isUseSsl() {
|
||||
return useSsl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password used for authenticating with the Redis server.
|
||||
*
|
||||
@@ -413,7 +439,6 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,6 +71,7 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -830,7 +831,12 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
connection.set("testitnow", "somethingelse");
|
||||
actual.add(connection.exec());
|
||||
actual.add(connection.get("testitnow"));
|
||||
verifyResults(Arrays.asList(new Object[] { null, "something" }));
|
||||
|
||||
if (connectionFactory instanceof JedisConnectionFactory) {
|
||||
verifyResults(Arrays.asList(new Object[] { Collections.emptyList(), "something" }));
|
||||
} else {
|
||||
verifyResults(Arrays.asList(new Object[] { null, "something" }));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -72,6 +72,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
* @author Christoph Strobl
|
||||
* @author Anqing Shao
|
||||
* @author Duobiao Ou
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class RedisTemplateTests<K, V> {
|
||||
@@ -785,7 +786,12 @@ public class RedisTemplateTests<K, V> {
|
||||
return operations.exec();
|
||||
}
|
||||
});
|
||||
assertNull(results);
|
||||
|
||||
if (redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory) {
|
||||
assertThat(results, is(empty()));
|
||||
} else {
|
||||
assertNull(results);
|
||||
}
|
||||
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value2));
|
||||
}
|
||||
|
||||
@@ -848,7 +854,13 @@ public class RedisTemplateTests<K, V> {
|
||||
return operations.exec();
|
||||
}
|
||||
});
|
||||
assertNull(results);
|
||||
|
||||
if (redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory) {
|
||||
assertThat(results, is(empty()));
|
||||
} else {
|
||||
assertNull(results);
|
||||
}
|
||||
|
||||
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value2));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user