Skip to content

Commit eb210a4

Browse files
DATAREDIS-506 - Polishing.
Make use of CollectionUtils and remove duplicate code paths. Original Pull Request: spring-projects#211
1 parent 836900e commit eb210a4

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.springframework.data.redis.core.types.RedisClientInfo;
6666
import org.springframework.util.Assert;
6767
import org.springframework.util.ClassUtils;
68+
import org.springframework.util.CollectionUtils;
6869
import org.springframework.util.ObjectUtils;
6970
import org.springframework.util.ReflectionUtils;
7071

@@ -770,7 +771,7 @@ public List<Object> exec() {
770771
throw new InvalidDataAccessApiUsageException("No ongoing transaction. Did you forget to call multi?");
771772
}
772773
List<Object> results = transaction.exec();
773-
return convertPipelineAndTxResults && results != null && !results.isEmpty()
774+
return convertPipelineAndTxResults && !CollectionUtils.isEmpty(results)
774775
? new TransactionResultConverter<Response<?>>(txResults, JedisConverters.exceptionConverter())
775776
.convert(results)
776777
: results;
@@ -3401,19 +3402,13 @@ public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
34013402
.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric());
34023403
try {
34033404
if (isPipelined()) {
3404-
pipeline(
3405-
new JedisResult(
3406-
pipeline.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
3407-
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())),
3408-
converter));
3405+
pipeline(new JedisResult(pipeline.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
3406+
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())), converter));
34093407
return null;
34103408
}
34113409
if (isQueueing()) {
3412-
transaction(
3413-
new JedisResult(
3414-
transaction.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
3415-
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())),
3416-
converter));
3410+
transaction(new JedisResult(transaction.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
3411+
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())), converter));
34173412
return null;
34183413
}
34193414

src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -266,18 +266,16 @@ protected Pool<Jedis> createRedisSentinelPool(RedisSentinelConfiguration config)
266266
*/
267267
protected Pool<Jedis> createRedisPool() {
268268

269-
return useSsl
270-
? new JedisPool(getPoolConfig(), getShardInfo().getHost(), getShardInfo().getPort(),
271-
getTimeoutFrom(getShardInfo()), getShardInfo().getPassword(), true)
272-
: new JedisPool(getPoolConfig(), getShardInfo().getHost(), getShardInfo().getPort(),
273-
getTimeoutFrom(getShardInfo()), getShardInfo().getPassword());
269+
return new JedisPool(getPoolConfig(), getShardInfo().getHost(), getShardInfo().getPort(),
270+
getTimeoutFrom(getShardInfo()), getShardInfo().getPassword(), useSsl);
274271
}
275272

276273
private JedisCluster createCluster() {
277274

278275
JedisCluster cluster = createCluster(this.clusterConfig, this.poolConfig);
279-
this.clusterCommandExecutor = new ClusterCommandExecutor(new JedisClusterConnection.JedisClusterTopologyProvider(
280-
cluster), new JedisClusterConnection.JedisClusterNodeResourceProvider(cluster), EXCEPTION_TRANSLATION);
276+
this.clusterCommandExecutor = new ClusterCommandExecutor(
277+
new JedisClusterConnection.JedisClusterTopologyProvider(cluster),
278+
new JedisClusterConnection.JedisClusterNodeResourceProvider(cluster), EXCEPTION_TRANSLATION);
281279
return cluster;
282280
}
283281

@@ -300,14 +298,8 @@ protected JedisCluster createCluster(RedisClusterConfiguration clusterConfig, Ge
300298

301299
int redirects = clusterConfig.getMaxRedirects() != null ? clusterConfig.getMaxRedirects().intValue() : 5;
302300

303-
if (poolConfig != null) {
304-
return StringUtils.hasText(getPassword())
305-
? new JedisCluster(hostAndPort, timeout, timeout, redirects, getPassword(), poolConfig)
306-
: new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
307-
}
308-
309301
return StringUtils.hasText(getPassword())
310-
? new JedisCluster(hostAndPort, timeout, timeout, redirects, getPassword(), poolConfig)
302+
? new JedisCluster(hostAndPort, timeout, timeout, redirects, password, poolConfig)
311303
: new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
312304
}
313305

@@ -349,8 +341,8 @@ public RedisConnection getConnection() {
349341
}
350342

351343
Jedis jedis = fetchJedisConnector();
352-
JedisConnection connection = (usePool ? new JedisConnection(jedis, pool, dbIndex) : new JedisConnection(jedis,
353-
null, dbIndex));
344+
JedisConnection connection = (usePool ? new JedisConnection(jedis, pool, dbIndex)
345+
: new JedisConnection(jedis, null, dbIndex));
354346
connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults);
355347
return postProcessConnection(connection);
356348
}

0 commit comments

Comments
 (0)