Skip to content

DATAREDIS-1214 - Fix null return value of GEODIST command. #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.0-DATAREDIS-1214-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,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 @@ -196,7 +197,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 @@ -176,7 +176,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 @@ -2704,6 +2704,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