DATAREDIS-1197 - Upgrade to Lettuce 6.0 RC1.
Adopt to API changes. Original Pull Request: #554
This commit is contained in:
committed by
Christoph Strobl
parent
51ea73afc6
commit
da5bab1fb2
@@ -26,6 +26,7 @@ import java.util.List;
|
||||
|
||||
import org.springframework.data.redis.connection.ReactiveScriptingCommands;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.util.ByteUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -80,7 +81,7 @@ class LettuceReactiveScriptingCommands implements ReactiveScriptingCommands {
|
||||
|
||||
Assert.notNull(script, "Script must not be null!");
|
||||
|
||||
return connection.execute(cmd -> cmd.scriptLoad(script)).next();
|
||||
return connection.execute(cmd -> cmd.scriptLoad(ByteUtils.getBytes(script))).next();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -21,15 +21,16 @@ import io.lettuce.core.XGroupCreateArgs;
|
||||
import io.lettuce.core.XReadArgs;
|
||||
import io.lettuce.core.XReadArgs.StreamOffset;
|
||||
import io.lettuce.core.cluster.api.reactive.RedisClusterReactiveCommands;
|
||||
import io.lettuce.core.models.stream.PendingMessage;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
|
||||
@@ -204,7 +205,7 @@ class LettuceReactiveStreamCommands implements ReactiveStreamCommands {
|
||||
.xgroupDelconsumer(command.getKey(),
|
||||
io.lettuce.core.Consumer.from(ByteUtils.getByteBuffer(command.getGroupName()),
|
||||
ByteUtils.getByteBuffer(command.getConsumerName())))
|
||||
.map(it -> new CommandResponse<>(command, Boolean.TRUE.equals(it) ? "OK" : "Error"));
|
||||
.map(it -> new CommandResponse<>(command, "OK"));
|
||||
}
|
||||
|
||||
if (command.getAction().equals(GroupCommandAction.DESTROY)) {
|
||||
@@ -243,25 +244,8 @@ class LettuceReactiveStreamCommands implements ReactiveStreamCommands {
|
||||
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
|
||||
|
||||
Assert.notNull(command.getKey(), "Key must not be null!");
|
||||
return cmd.xpending(command.getKey(), ByteUtils.getByteBuffer(command.getGroupName())).collectList().map(it -> {
|
||||
|
||||
// begin
|
||||
// {* hacking *}
|
||||
// while (https://github.com/lettuce-io/lettuce-core/issues/1229 != resolved) begin
|
||||
|
||||
ArrayList<Object> target = new ArrayList<>(it);
|
||||
if (target.size() == 2 && target.get(1) instanceof List) {
|
||||
target.add(1, null);
|
||||
target.add(1, null);
|
||||
}
|
||||
while (target.size() < 4) {
|
||||
target.add(null);
|
||||
}
|
||||
|
||||
// end.
|
||||
// end.
|
||||
|
||||
return StreamConverters.toPendingMessagesInfo(command.getGroupName(), target);
|
||||
return cmd.xpending(command.getKey(), ByteUtils.getByteBuffer(command.getGroupName())).map(it -> {
|
||||
return StreamConverters.toPendingMessagesInfo(command.getGroupName(), it);
|
||||
}).map(value -> new CommandResponse<>(command, value));
|
||||
}));
|
||||
}
|
||||
@@ -282,7 +266,7 @@ class LettuceReactiveStreamCommands implements ReactiveStreamCommands {
|
||||
io.lettuce.core.Limit limit = command.isLimited() ? io.lettuce.core.Limit.from(command.getCount())
|
||||
: io.lettuce.core.Limit.unlimited();
|
||||
|
||||
Flux<Object> publisher = command.hasConsumer() ? cmd.xpending(command.getKey(),
|
||||
Flux<PendingMessage> publisher = command.hasConsumer() ? cmd.xpending(command.getKey(),
|
||||
io.lettuce.core.Consumer.from(groupName, ByteUtils.getByteBuffer(command.getConsumerName())), range, limit)
|
||||
: cmd.xpending(command.getKey(), groupName, range, limit);
|
||||
|
||||
@@ -353,7 +337,7 @@ class LettuceReactiveStreamCommands implements ReactiveStreamCommands {
|
||||
.map(it -> StreamRecords.newRecord().in(it.getStream()).withId(it.getId()).ofBuffer(it.getBody()));
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveStreamCommands#xInfo(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@@ -370,7 +354,7 @@ class LettuceReactiveStreamCommands implements ReactiveStreamCommands {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveStreamCommands#xInfoGroups(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@@ -386,7 +370,7 @@ class LettuceReactiveStreamCommands implements ReactiveStreamCommands {
|
||||
}));
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveStreamCommands#xInfoConsumers(org.reactivestreams.Publisher)
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -268,14 +269,16 @@ class LettuceStreamCommands implements RedisStreamCommands {
|
||||
io.lettuce.core.Consumer<byte[]> lettuceConsumer = toConsumer(consumer);
|
||||
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newLettuceResult(getAsyncConnection().xgroupDelconsumer(key, lettuceConsumer)));
|
||||
pipeline(connection.newLettuceResult(getAsyncConnection().xgroupDelconsumer(key, lettuceConsumer),
|
||||
Objects::nonNull));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newLettuceResult(getAsyncConnection().xgroupDelconsumer(key, lettuceConsumer)));
|
||||
transaction(connection.newLettuceResult(getAsyncConnection().xgroupDelconsumer(key, lettuceConsumer),
|
||||
Objects::nonNull));
|
||||
return null;
|
||||
}
|
||||
return getConnection().xgroupDelconsumer(key, lettuceConsumer);
|
||||
return Objects.nonNull(getConnection().xgroupDelconsumer(key, lettuceConsumer));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import io.lettuce.core.XClaimArgs;
|
||||
import io.lettuce.core.XReadArgs;
|
||||
import io.lettuce.core.models.stream.PendingMessage;
|
||||
import io.lettuce.core.models.stream.PendingMessages;
|
||||
import io.lettuce.core.models.stream.PendingParser;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.Duration;
|
||||
@@ -51,19 +50,17 @@ import org.springframework.util.NumberUtils;
|
||||
* @author Christoph Strobl
|
||||
* @since 2.2
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
class StreamConverters {
|
||||
|
||||
private static final Converter<List<StreamMessage<byte[], byte[]>>, List<RecordId>> MESSAGEs_TO_IDs = new ListConverter<>(
|
||||
messageToIdConverter());
|
||||
|
||||
private static final BiFunction<List<Object>, String, org.springframework.data.redis.connection.stream.PendingMessages> PENDING_MESSAGES_CONVERTER = (
|
||||
private static final BiFunction<List<PendingMessage>, String, org.springframework.data.redis.connection.stream.PendingMessages> PENDING_MESSAGES_CONVERTER = (
|
||||
source, groupName) -> {
|
||||
|
||||
List<Object> target = source.stream().map(StreamConverters::preConvertNativeValues).collect(Collectors.toList());
|
||||
List<PendingMessage> pendingMessages = PendingParser.parseRange(target);
|
||||
|
||||
List<org.springframework.data.redis.connection.stream.PendingMessage> messages = pendingMessages.stream()
|
||||
List<org.springframework.data.redis.connection.stream.PendingMessage> messages = source.stream()
|
||||
.map(it -> {
|
||||
|
||||
RecordId id = RecordId.of(it.getId());
|
||||
@@ -78,17 +75,15 @@ class StreamConverters {
|
||||
|
||||
};
|
||||
|
||||
private static final BiFunction<List<Object>, String, PendingMessagesSummary> PENDING_MESSAGES_SUMMARY_CONVERTER = (
|
||||
private static final BiFunction<PendingMessages, String, PendingMessagesSummary> PENDING_MESSAGES_SUMMARY_CONVERTER = (
|
||||
source, groupName) -> {
|
||||
|
||||
List<Object> target = source.stream().map(StreamConverters::preConvertNativeValues).collect(Collectors.toList());
|
||||
org.springframework.data.domain.Range<String> range = source.getMessageIds().isUnbounded()
|
||||
? org.springframework.data.domain.Range.unbounded()
|
||||
: org.springframework.data.domain.Range.open(source.getMessageIds().getLower().getValue(),
|
||||
source.getMessageIds().getUpper().getValue());
|
||||
|
||||
PendingMessages pendingMessages = PendingParser.parse(target);
|
||||
org.springframework.data.domain.Range<String> range = org.springframework.data.domain.Range.open(
|
||||
pendingMessages.getMessageIds().getLower().getValue(), pendingMessages.getMessageIds().getUpper().getValue());
|
||||
|
||||
return new PendingMessagesSummary(groupName, pendingMessages.getCount(), range,
|
||||
pendingMessages.getConsumerMessageCount());
|
||||
return new PendingMessagesSummary(groupName, source.getCount(), range, source.getConsumerMessageCount());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -138,7 +133,7 @@ class StreamConverters {
|
||||
* @since 2.3
|
||||
*/
|
||||
static org.springframework.data.redis.connection.stream.PendingMessages toPendingMessages(String groupName,
|
||||
org.springframework.data.domain.Range<?> range, List<Object> source) {
|
||||
org.springframework.data.domain.Range<?> range, List<PendingMessage> source) {
|
||||
return PENDING_MESSAGES_CONVERTER.apply(source, groupName).withinRange(range);
|
||||
}
|
||||
|
||||
@@ -150,7 +145,7 @@ class StreamConverters {
|
||||
* @return
|
||||
* @since 2.3
|
||||
*/
|
||||
static PendingMessagesSummary toPendingMessagesInfo(String groupName, List<Object> source) {
|
||||
static PendingMessagesSummary toPendingMessagesInfo(String groupName, PendingMessages source) {
|
||||
return PENDING_MESSAGES_SUMMARY_CONVERTER.apply(source, groupName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user