-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Terminate stream with error on null
values returned by RedisElementReader
for top-level elements
#2672
Terminate stream with error on null
values returned by RedisElementReader
for top-level elements
#2672
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,13 @@ | |
import java.util.function.Function; | ||
|
||
import org.reactivestreams.Publisher; | ||
import org.springframework.dao.InvalidDataAccessApiUsageException; | ||
import org.springframework.data.redis.connection.ReactiveListCommands; | ||
import org.springframework.data.redis.connection.ReactiveListCommands.Direction; | ||
import org.springframework.data.redis.connection.ReactiveListCommands.LPosCommand; | ||
import org.springframework.data.redis.connection.RedisListCommands.Position; | ||
import org.springframework.data.redis.serializer.RedisSerializationContext; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
|
@@ -58,7 +60,7 @@ public Flux<V> range(K key, long start, long end) { | |
|
||
Assert.notNull(key, "Key must not be null"); | ||
|
||
return createFlux(connection -> connection.lRange(rawKey(key), start, end).map(this::readValue)); | ||
return createFlux(connection -> connection.lRange(rawKey(key), start, end).map(this::readRequiredValue)); | ||
} | ||
|
||
@Override | ||
|
@@ -170,7 +172,8 @@ public Mono<V> move(K sourceKey, Direction from, K destinationKey, Direction to) | |
Assert.notNull(to, "To direction must not be null"); | ||
|
||
return createMono( | ||
connection -> connection.lMove(rawKey(sourceKey), rawKey(destinationKey), from, to).map(this::readValue)); | ||
connection -> connection.lMove(rawKey(sourceKey), rawKey(destinationKey), from, to) | ||
.map(this::readRequiredValue)); | ||
} | ||
|
||
@Override | ||
|
@@ -183,7 +186,7 @@ public Mono<V> move(K sourceKey, Direction from, K destinationKey, Direction to, | |
Assert.notNull(timeout, "Timeout must not be null"); | ||
|
||
return createMono(connection -> connection.bLMove(rawKey(sourceKey), rawKey(destinationKey), from, to, timeout) | ||
.map(this::readValue)); | ||
.map(this::readRequiredValue)); | ||
} | ||
|
||
@Override | ||
|
@@ -208,7 +211,7 @@ public Mono<V> index(K key, long index) { | |
|
||
Assert.notNull(key, "Key must not be null"); | ||
|
||
return createMono(connection -> connection.lIndex(rawKey(key), index).map(this::readValue)); | ||
return createMono(connection -> connection.lIndex(rawKey(key), index).map(this::readRequiredValue)); | ||
} | ||
|
||
@Override | ||
|
@@ -232,7 +235,7 @@ public Mono<V> leftPop(K key) { | |
|
||
Assert.notNull(key, "Key must not be null"); | ||
|
||
return createMono(connection -> connection.lPop(rawKey(key)).map(this::readValue)); | ||
return createMono(connection -> connection.lPop(rawKey(key)).map(this::readRequiredValue)); | ||
|
||
} | ||
|
||
|
@@ -244,15 +247,15 @@ public Mono<V> leftPop(K key, Duration timeout) { | |
Assert.isTrue(isZeroOrGreater1Second(timeout), "Duration must be either zero or greater or equal to 1 second"); | ||
|
||
return createMono(connection -> connection.blPop(Collections.singletonList(rawKey(key)), timeout) | ||
.map(popResult -> readValue(popResult.getValue()))); | ||
.mapNotNull(popResult -> readValue(popResult.getValue()))); | ||
} | ||
|
||
@Override | ||
public Mono<V> rightPop(K key) { | ||
|
||
Assert.notNull(key, "Key must not be null"); | ||
|
||
return createMono(connection -> connection.rPop(rawKey(key)).map(this::readValue)); | ||
return createMono(connection -> connection.rPop(rawKey(key)).map(this::readRequiredValue)); | ||
} | ||
|
||
@Override | ||
|
@@ -263,7 +266,7 @@ public Mono<V> rightPop(K key, Duration timeout) { | |
Assert.isTrue(isZeroOrGreater1Second(timeout), "Duration must be either zero or greater or equal to 1 second"); | ||
|
||
return createMono(connection -> connection.brPop(Collections.singletonList(rawKey(key)), timeout) | ||
.map(popResult -> readValue(popResult.getValue()))); | ||
.mapNotNull(popResult -> readValue(popResult.getValue()))); | ||
} | ||
|
||
@Override | ||
|
@@ -273,7 +276,7 @@ public Mono<V> rightPopAndLeftPush(K sourceKey, K destinationKey) { | |
Assert.notNull(destinationKey, "Destination key must not be null"); | ||
|
||
return createMono( | ||
connection -> connection.rPopLPush(rawKey(sourceKey), rawKey(destinationKey)).map(this::readValue)); | ||
connection -> connection.rPopLPush(rawKey(sourceKey), rawKey(destinationKey)).map(this::readRequiredValue)); | ||
} | ||
|
||
@Override | ||
|
@@ -285,7 +288,8 @@ public Mono<V> rightPopAndLeftPush(K sourceKey, K destinationKey, Duration timeo | |
Assert.isTrue(isZeroOrGreater1Second(timeout), "Duration must be either zero or greater or equal to 1 second"); | ||
|
||
return createMono( | ||
connection -> connection.bRPopLPush(rawKey(sourceKey), rawKey(destinationKey), timeout).map(this::readValue)); | ||
connection -> connection.bRPopLPush(rawKey(sourceKey), rawKey(destinationKey), timeout) | ||
.map(this::readRequiredValue)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous variant was There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This previous variant was I was thinking more along the lines of the But, perhaps the choice of simply |
||
} | ||
|
||
@Override | ||
|
@@ -322,7 +326,19 @@ private ByteBuffer rawValue(V value) { | |
return serializationContext.getValueSerializationPair().write(value); | ||
} | ||
|
||
@Nullable | ||
private V readValue(ByteBuffer buffer) { | ||
return serializationContext.getValueSerializationPair().read(buffer); | ||
} | ||
|
||
private V readRequiredValue(ByteBuffer buffer) { | ||
|
||
V v = readValue(buffer); | ||
|
||
if (v == null) { | ||
throw new InvalidDataAccessApiUsageException("Deserialized list value is null"); | ||
} | ||
|
||
return v; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me the
geoDist(..)
methods inReactiveGeoOperations
for theGEODIST
command variations should be protected in the case of returningnull
.While the arguments passed to the
ReactiveGeoOperations.distance(..)
methods used in the computation of the geo distance calculation may not benull
, themember
argument may also not have been geocoded in Redis with thegeoAdd(..)
command properly (which I think is a prerequisite based on the docs).Therefore, in the case of a "missing" member (or element) the
GEODIST
command returnsnull
as documented.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, perhaps,
ReactiveGeoOperations
needs further refinements down the road, particularly with guards around possiblenull
values.