Skip to content

Commit

Permalink
DATAREDIS-1214 - Fix null return value of GEODIST command.
Browse files Browse the repository at this point in the history
Original pull request: #565.
  • Loading branch information
christophstrobl authored and mp911de committed Oct 5, 2020
1 parent f0d3307 commit 1866415
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
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);
}
Expand Down Expand Up @@ -195,7 +196,8 @@ public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metri
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metri
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,19 @@ public void geoDist() {
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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ public void geoDistShouldReturnDistanceInFeeCorrectly() {
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() {

Expand Down

0 comments on commit 1866415

Please sign in to comment.