Skip to content

Commit d0df07a

Browse files
christophstroblmp911de
authored andcommitted
Fix null return value of GEODIST command.
1 parent 3f38066 commit d0df07a

File tree

2 files changed

+80
-16
lines changed

2 files changed

+80
-16
lines changed

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.concurrent.Future;
5454
import java.util.concurrent.TimeUnit;
5555
import java.util.concurrent.atomic.AtomicLong;
56+
import java.util.function.Function;
5657
import java.util.function.Supplier;
5758

5859
import org.springframework.beans.BeanUtils;
@@ -936,6 +937,79 @@ void pipeline(LettuceResult result) {
936937
}
937938
}
938939

940+
<S, T> void executeInPipeline(Function<RedisClusterAsyncCommands, RedisFuture<S>> command,
941+
Converter<S, T> converter) {
942+
943+
try {
944+
pipeline(newLettuceResult(command.apply(getAsyncConnection()), converter));
945+
} catch (Exception ex) {
946+
throw convertLettuceAccessException(ex);
947+
}
948+
}
949+
950+
<S, T> void executeInTx(Function<RedisClusterAsyncCommands, RedisFuture<S>> command, Converter<S, T> converter) {
951+
952+
try {
953+
transaction(newLettuceResult(command.apply(getAsyncConnection()), converter));
954+
} catch (Exception ex) {
955+
throw convertLettuceAccessException(ex);
956+
}
957+
}
958+
959+
<T> NullableResult<T> execute(Function<RedisClusterCommands, T> command) {
960+
961+
try {
962+
963+
T result = command.apply(getConnection());
964+
return NullableResult.of(result);
965+
} catch (Exception ex) {
966+
throw convertLettuceAccessException(ex);
967+
}
968+
}
969+
970+
<T> RedisFuture<T> executeAsync(Function<RedisClusterAsyncCommands, RedisFuture<T>> command) {
971+
972+
try {
973+
return command.apply(getAsyncConnection());
974+
} catch (Exception ex) {
975+
throw convertLettuceAccessException(ex);
976+
}
977+
}
978+
979+
<S, T> T invoke(RedisFuture<S> future, Converter<S, T> converter) {
980+
981+
if (isPipelined()) {
982+
pipeline(newLettuceResult(future, converter));
983+
return null;
984+
}
985+
if (isQueueing()) {
986+
transaction(newLettuceResult(future, converter));
987+
return null;
988+
}
989+
return NullableResult.of((S) await(future)).convert(converter).get();
990+
}
991+
992+
<T> T execute(Function<RedisClusterCommands, T> sync, Function<RedisClusterAsyncCommands, RedisFuture<T>> async) {
993+
return execute(sync, async, val -> val);
994+
}
995+
996+
// use a future here and only async.
997+
<S, T> T execute(Function<RedisClusterCommands, S> sync, Function<RedisClusterAsyncCommands, RedisFuture<S>> async,
998+
Converter<S, T> converter) {
999+
1000+
if (isPipelined()) {
1001+
executeInPipeline(async, converter);
1002+
return null;
1003+
}
1004+
if (isQueueing()) {
1005+
executeInTx(async, converter);
1006+
return null;
1007+
}
1008+
1009+
// return execute(sync).convert(converter).get();
1010+
return NullableResult.of((S) await(executeAsync(async))).convert(converter).get();
1011+
}
1012+
9391013
void transaction(FutureResult<?> result) {
9401014
txResults.add(result);
9411015
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceGeoCommands.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.data.geo.GeoResults;
3737
import org.springframework.data.geo.Metric;
3838
import org.springframework.data.geo.Point;
39+
import org.springframework.data.redis.connection.NullableResult;
3940
import org.springframework.data.redis.connection.RedisGeoCommands;
4041
import org.springframework.data.redis.connection.convert.ListConverter;
4142
import org.springframework.lang.Nullable;
@@ -165,23 +166,12 @@ public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metri
165166
GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(metric);
166167
Converter<Double, Distance> distanceConverter = LettuceConverters.distanceConverterForMetric(metric);
167168

168-
try {
169-
if (isPipelined()) {
170-
pipeline(connection.newLettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit),
171-
distanceConverter));
172-
return null;
173-
}
174-
if (isQueueing()) {
175-
transaction(connection.newLettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit),
176-
distanceConverter));
177-
return null;
178-
}
169+
// return connection.execute(
170+
// sync -> sync.geodist(key, member1, member2, geoUnit),
171+
// async -> async.geodist(key, member1, member2, geoUnit),
172+
// distanceConverter);
179173

180-
Double distance = getConnection().geodist(key, member1, member2, geoUnit);
181-
return distance != null ? distanceConverter.convert(distance) : null;
182-
} catch (Exception ex) {
183-
throw convertLettuceAccessException(ex);
184-
}
174+
return connection.invoke(connection.getAsyncConnection().geodist(key, member1, member2, geoUnit), distanceConverter);
185175
}
186176

187177
/*

0 commit comments

Comments
 (0)