DATAREDIS-1223 - Upgrade to Lettuce 6.0 GA.

Adopt HashCommands to changed HGETALL method signature returning Flux<KeyValue> instead of Mono<Map>.
This commit is contained in:
Mark Paluch
2020-10-05 11:43:03 +02:00
parent f1d88484fd
commit b26a93280a
2 changed files with 25 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.reactivestreams.Publisher;
import org.springframework.data.redis.connection.ReactiveHashCommands;
import org.springframework.data.redis.connection.ReactiveRedisConnection.BooleanResponse;
import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse;
@@ -209,9 +210,9 @@ class LettuceReactiveHashCommands implements ReactiveHashCommands {
Assert.notNull(command.getKey(), "Key must not be null!");
Mono<Map<ByteBuffer, ByteBuffer>> result = cmd.hgetall(command.getKey());
Flux<KeyValue<ByteBuffer, ByteBuffer>> result = cmd.hgetall(command.getKey());
return Mono.just(new CommandResponse<>(command, result.flatMapMany(v -> Flux.fromStream(v.entrySet().stream()))));
return Mono.just(new CommandResponse<>(command, result.map(LettuceReactiveHashCommands::toEntry)));
}));
}
@@ -268,4 +269,25 @@ class LettuceReactiveHashCommands implements ReactiveHashCommands {
return cmd.hstrlen(command.getKey(), command.getField()).map(value -> new NumericResponse<>(command, value));
}));
}
private static Map.Entry<ByteBuffer, ByteBuffer> toEntry(KeyValue<ByteBuffer, ByteBuffer> kv) {
return new Entry<ByteBuffer, ByteBuffer>() {
@Override
public ByteBuffer getKey() {
return kv.getKey();
}
@Override
public ByteBuffer getValue() {
return kv.getValue();
}
@Override
public ByteBuffer setValue(ByteBuffer value) {
throw new UnsupportedOperationException("Cannot set value for entry");
}
};
}
}