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:
Mark Paluch
2016-07-25 15:28:39 +02:00
committed by Christoph Strobl
parent 34f2d95669
commit 1a332c0f57
6 changed files with 58 additions and 14 deletions

View File

@@ -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;

View File

@@ -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;
}
/**