DATAREDIS-1214 - Fix null return value of GEODIST command.
Original pull request: #565.
This commit is contained in:
committed by
Mark Paluch
parent
c3a9153532
commit
9f1de929a4
@@ -162,7 +162,8 @@ class JedisGeoCommands implements RedisGeoCommands {
|
||||
return null;
|
||||
}
|
||||
|
||||
return distanceConverter.convert(connection.getJedis().geodist(key, member1, member2));
|
||||
Double distance = connection.getJedis().geodist(key, member1, member2);
|
||||
return distance != null ? distanceConverter.convert(distance) : null;
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -195,7 +196,8 @@ class JedisGeoCommands implements RedisGeoCommands {
|
||||
return null;
|
||||
}
|
||||
|
||||
return distanceConverter.convert(connection.getJedis().geodist(key, member1, member2, geoUnit));
|
||||
Double distance = connection.getJedis().geodist(key, member1, member2, geoUnit);
|
||||
return distance != null ? distanceConverter.convert(distance) : null;
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,9 @@ class LettuceGeoCommands implements RedisGeoCommands {
|
||||
distanceConverter));
|
||||
return null;
|
||||
}
|
||||
return distanceConverter.convert(getConnection().geodist(key, member1, member2, geoUnit));
|
||||
|
||||
Double distance = getConnection().geodist(key, member1, member2, geoUnit);
|
||||
return distance != null ? distanceConverter.convert(distance) : null;
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -2631,6 +2631,19 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
assertThat(((Distance) result.get(1)).getUnit()).isEqualTo("m");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1214
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||
public void geoDistNotExisting() {
|
||||
|
||||
String key = "geo-" + UUID.randomUUID();
|
||||
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
|
||||
actual.add(connection.geoDist(key, "Spring", "Data"));
|
||||
|
||||
List<Object> result = getResults();
|
||||
assertThat(result.get(1)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-438
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||
|
||||
@@ -186,6 +186,22 @@ public class DefaultGeoOperationsTests<K, M> {
|
||||
assertThat(dist.getUnit()).isEqualTo("ft");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1214
|
||||
public void geoDistShouldReturnNullIfNoDistanceCalculable() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
M member1 = valueFactory.instance();
|
||||
M member2 = valueFactory.instance();
|
||||
M member3 = valueFactory.instance();
|
||||
M member4 = valueFactory.instance();
|
||||
|
||||
geoOperations.add(key, POINT_PALERMO, member1);
|
||||
geoOperations.add(key, POINT_CATANIA, member2);
|
||||
|
||||
Distance dist = geoOperations.distance(key, member3, member4, DistanceUnit.FEET);
|
||||
assertThat(dist).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-438, DATAREDIS-614
|
||||
public void testGeoHash() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user