DATAREDIS-1226 - Polishing.

Remove justId from XClaimOptions and set the flag inside xClaimJustId to avoid errors when processing justId inside xClaim having a different return type.

Original Pull Request: #567
This commit is contained in:
Christoph Strobl
2020-10-07 10:44:38 +02:00
parent d2dce680cc
commit 3920890c01
6 changed files with 52 additions and 38 deletions

View File

@@ -229,7 +229,6 @@ public interface RedisStreamCommands {
/**
* @author Christoph Strobl
* @author Dengliming
* @since 2.3
*/
class XClaimOptions {
@@ -240,10 +239,9 @@ public interface RedisStreamCommands {
private final @Nullable Instant unixTime;
private final @Nullable Long retryCount;
private final boolean force;
private final boolean justId;
private XClaimOptions(List<RecordId> ids, Duration minIdleTime, @Nullable Duration idleTime,
@Nullable Instant unixTime, @Nullable Long retryCount, boolean force, boolean justId) {
@Nullable Instant unixTime, @Nullable Long retryCount, boolean force) {
this.ids = new ArrayList<>(ids);
this.minIdleTime = minIdleTime;
@@ -251,7 +249,6 @@ public interface RedisStreamCommands {
this.unixTime = unixTime;
this.retryCount = retryCount;
this.force = force;
this.justId = justId;
}
/**
@@ -284,7 +281,7 @@ public interface RedisStreamCommands {
* @return {@code this}.
*/
public XClaimOptions idle(Duration idleTime) {
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, force, justId);
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, force);
}
/**
@@ -295,7 +292,7 @@ public interface RedisStreamCommands {
* @return {@code this}.
*/
public XClaimOptions time(Instant unixTime) {
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, force, justId);
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, force);
}
/**
@@ -305,7 +302,7 @@ public interface RedisStreamCommands {
* @return new instance of {@link XClaimOptions}.
*/
public XClaimOptions retryCount(long retryCount) {
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, force, justId);
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, force);
}
/**
@@ -315,16 +312,7 @@ public interface RedisStreamCommands {
* @return new instance of {@link XClaimOptions}.
*/
public XClaimOptions force() {
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, true, justId);
}
/**
* Set the JUSTID flag.
*
* @return new instance of {@link XClaimOptions}.
*/
public XClaimOptions justId() {
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, force, true);
return new XClaimOptions(ids, minIdleTime, idleTime, unixTime, retryCount, true);
}
/**
@@ -393,15 +381,6 @@ public interface RedisStreamCommands {
return force;
}
/**
* Get the JUSTID flag.
*
* @return
*/
public boolean isJustId() {
return justId;
}
public static class XClaimOptionsBuilder {
private final Duration minIdleTime;
@@ -425,7 +404,7 @@ public interface RedisStreamCommands {
.map(it -> it instanceof RecordId ? (RecordId) it : RecordId.of(it.toString()))
.collect(Collectors.toList());
return new XClaimOptions(idList, minIdleTime, null, null, null, false, false);
return new XClaimOptions(idList, minIdleTime, null, null, null, false);
}
/**

View File

@@ -128,8 +128,7 @@ class LettuceReactiveStreamCommands implements ReactiveStreamCommands {
String[] ids = command.getOptions().getIdsAsStringArray();
io.lettuce.core.Consumer<ByteBuffer> from = io.lettuce.core.Consumer
.from(ByteUtils.getByteBuffer(command.getGroupName()), ByteUtils.getByteBuffer(command.getNewOwner()));
XClaimArgs args = StreamConverters.toXClaimArgs(command.getOptions());
XClaimArgs args = StreamConverters.toXClaimArgs(command.getOptions()).justid();
Flux<RecordId> result = cmd.xclaim(command.getKey(), from, args, ids).map(it -> RecordId.of(it.getId()));
return new CommandResponse<>(command, result);
}));

View File

@@ -135,7 +135,7 @@ class LettuceStreamCommands implements RedisStreamCommands {
String[] ids = options.getIdsAsStringArray();
io.lettuce.core.Consumer<byte[]> from = io.lettuce.core.Consumer.from(LettuceConverters.toBytes(group),
LettuceConverters.toBytes(newOwner));
XClaimArgs args = StreamConverters.toXClaimArgs(options);
XClaimArgs args = StreamConverters.toXClaimArgs(options).justid();
try {
if (isPipelined()) {

View File

@@ -236,9 +236,6 @@ class StreamConverters {
if (source.getUnixTime() != null) {
args.time(source.getUnixTime());
}
if (source.isJustId()) {
args.justid();
}
return args;
}