DATAREDIS-506 - Polishing.

Make use of CollectionUtils and remove duplicate code paths.

Original Pull Request: #211
This commit is contained in:
Christoph Strobl
2016-07-26 15:09:13 +02:00
parent 836900e034
commit eb210a4b8a
2 changed files with 14 additions and 27 deletions

View File

@@ -65,6 +65,7 @@ import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@@ -770,7 +771,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 && results != null && !results.isEmpty()
return convertPipelineAndTxResults && !CollectionUtils.isEmpty(results)
? new TransactionResultConverter<Response<?>>(txResults, JedisConverters.exceptionConverter())
.convert(results)
: results;
@@ -3401,19 +3402,13 @@ public class JedisConnection extends AbstractRedisConnection {
.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric());
try {
if (isPipelined()) {
pipeline(
new JedisResult(
pipeline.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())),
converter));
pipeline(new JedisResult(pipeline.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())), converter));
return null;
}
if (isQueueing()) {
transaction(
new JedisResult(
transaction.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())),
converter));
transaction(new JedisResult(transaction.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())), converter));
return null;
}

View File

@@ -266,18 +266,16 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
*/
protected Pool<Jedis> createRedisPool() {
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());
return new JedisPool(getPoolConfig(), getShardInfo().getHost(), getShardInfo().getPort(),
getTimeoutFrom(getShardInfo()), getShardInfo().getPassword(), useSsl);
}
private JedisCluster createCluster() {
JedisCluster cluster = createCluster(this.clusterConfig, this.poolConfig);
this.clusterCommandExecutor = new ClusterCommandExecutor(new JedisClusterConnection.JedisClusterTopologyProvider(
cluster), new JedisClusterConnection.JedisClusterNodeResourceProvider(cluster), EXCEPTION_TRANSLATION);
this.clusterCommandExecutor = new ClusterCommandExecutor(
new JedisClusterConnection.JedisClusterTopologyProvider(cluster),
new JedisClusterConnection.JedisClusterNodeResourceProvider(cluster), EXCEPTION_TRANSLATION);
return cluster;
}
@@ -300,14 +298,8 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
int redirects = clusterConfig.getMaxRedirects() != null ? clusterConfig.getMaxRedirects().intValue() : 5;
if (poolConfig != null) {
return StringUtils.hasText(getPassword())
? new JedisCluster(hostAndPort, timeout, timeout, redirects, getPassword(), poolConfig)
: new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
}
return StringUtils.hasText(getPassword())
? new JedisCluster(hostAndPort, timeout, timeout, redirects, getPassword(), poolConfig)
? new JedisCluster(hostAndPort, timeout, timeout, redirects, password, poolConfig)
: new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
}
@@ -349,8 +341,8 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
}
Jedis jedis = fetchJedisConnector();
JedisConnection connection = (usePool ? new JedisConnection(jedis, pool, dbIndex) : new JedisConnection(jedis,
null, dbIndex));
JedisConnection connection = (usePool ? new JedisConnection(jedis, pool, dbIndex)
: new JedisConnection(jedis, null, dbIndex));
connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults);
return postProcessConnection(connection);
}