Switch to TimeoutUtils for zsetcommands.
Remove precise timeout calculation in zsetcommands and switch to TimeoutUtils and update a bit of docs and add some new lines here and there. Original Pull Request: #2107
This commit is contained in:
@@ -671,6 +671,7 @@ public interface ReactiveListCommands {
|
||||
|
||||
public LMoveCommand(@Nullable ByteBuffer sourceKey, @Nullable ByteBuffer destinationKey, @Nullable Direction from,
|
||||
@Nullable Direction to) {
|
||||
|
||||
super(sourceKey);
|
||||
this.destinationKey = destinationKey;
|
||||
this.from = from;
|
||||
@@ -697,15 +698,15 @@ public interface ReactiveListCommands {
|
||||
* properties.
|
||||
*
|
||||
* @param destinationKey must not be {@literal null}.
|
||||
* @param to must not be {@literal null}.
|
||||
* @param direction must not be {@literal null}.
|
||||
* @return a new {@link LMoveCommand} with {@literal pivot} applied.
|
||||
*/
|
||||
public LMoveCommand to(ByteBuffer destinationKey, Direction destinationDirection) {
|
||||
public LMoveCommand to(ByteBuffer destinationKey, Direction direction) {
|
||||
|
||||
Assert.notNull(destinationKey, "Destination key must not be null!");
|
||||
Assert.notNull(destinationDirection, "Direction must not be null!");
|
||||
Assert.notNull(direction, "Direction must not be null!");
|
||||
|
||||
return new LMoveCommand(getKey(), destinationKey, from, destinationDirection);
|
||||
return new LMoveCommand(getKey(), destinationKey, from, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,7 @@ public interface RedisListCommands {
|
||||
* @since 2.6
|
||||
*/
|
||||
enum Direction {
|
||||
|
||||
LEFT, RIGHT;
|
||||
|
||||
/**
|
||||
|
||||
@@ -876,7 +876,7 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @param timeout
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/lmove">Redis Documentation: BLMOVE</a>
|
||||
* @see <a href="https://redis.io/commands/blmove">Redis Documentation: BLMOVE</a>
|
||||
* @see #lMove(byte[], byte[], Direction, Direction)
|
||||
* @see #bLMove(byte[], byte[], Direction, Direction, double)
|
||||
*/
|
||||
|
||||
@@ -1028,23 +1028,17 @@ public abstract class LettuceConverters extends Converters {
|
||||
|
||||
static LMoveArgs toLmoveArgs(Enum<?> from, Enum<?> to) {
|
||||
|
||||
if (from.name().equals(Direction.LEFT.name()) && to.name().equals(Direction.LEFT.name())) {
|
||||
return LMoveArgs.Builder.leftLeft();
|
||||
}
|
||||
|
||||
if (from.name().equals(Direction.LEFT.name()) && to.name().equals(Direction.RIGHT.name())) {
|
||||
if (from.name().equals(Direction.LEFT.name())) {
|
||||
if (to.name().equals(Direction.LEFT.name())) {
|
||||
return LMoveArgs.Builder.leftLeft();
|
||||
}
|
||||
return LMoveArgs.Builder.leftRight();
|
||||
}
|
||||
|
||||
if (from.name().equals(Direction.RIGHT.name()) && to.name().equals(Direction.LEFT.name())) {
|
||||
if (to.name().equals(Direction.LEFT.name())) {
|
||||
return LMoveArgs.Builder.rightLeft();
|
||||
}
|
||||
|
||||
if (from.name().equals(Direction.RIGHT.name()) && to.name().equals(Direction.RIGHT.name())) {
|
||||
return LMoveArgs.Builder.rightRight();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("Unsupported combination of arguments: %s/%s", from, to));
|
||||
return LMoveArgs.Builder.rightRight();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.lettuce.core.ScoredValue;
|
||||
import io.lettuce.core.Value;
|
||||
import io.lettuce.core.ZAddArgs;
|
||||
import io.lettuce.core.ZStoreArgs;
|
||||
import org.springframework.data.redis.core.TimeoutUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -415,7 +416,7 @@ class LettuceReactiveZSetCommands implements ReactiveZSetCommands {
|
||||
|
||||
if(command.getTimeUnit() == TimeUnit.MILLISECONDS) {
|
||||
|
||||
double timeout = preciseTimeout(command.getTimeout(), command.getTimeUnit());
|
||||
double timeout = TimeoutUtils.toDoubleSeconds(command.getTimeout(), command.getTimeUnit());
|
||||
|
||||
Mono<ScoredValue<ByteBuffer>> result = (command.getDirection() == PopDirection.MIN
|
||||
? cmd.bzpopmin(timeout, command.getKey())
|
||||
@@ -807,10 +808,6 @@ class LettuceReactiveZSetCommands implements ReactiveZSetCommands {
|
||||
return new DefaultTuple(ByteUtils.getBytes(value), score);
|
||||
}
|
||||
|
||||
static double preciseTimeout(long val, TimeUnit unit) {
|
||||
return (double) unit.toMillis(val) / 1000.0D;
|
||||
}
|
||||
|
||||
protected LettuceReactiveRedisConnection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.KeyBoundCursor;
|
||||
import org.springframework.data.redis.core.ScanIteration;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.TimeoutUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -370,7 +371,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
if(TimeUnit.MILLISECONDS == unit) {
|
||||
|
||||
return connection.invoke(connection.getAsyncDedicatedConnection())
|
||||
.from(RedisSortedSetAsyncCommands::bzpopmin, preciseTimeout(timeout, unit), key)
|
||||
.from(RedisSortedSetAsyncCommands::bzpopmin, TimeoutUtils.toDoubleSeconds(timeout, unit), key)
|
||||
.get(it -> it.map(LettuceConverters::toTuple).getValueOrElse(null));
|
||||
}
|
||||
|
||||
@@ -420,7 +421,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
if(TimeUnit.MILLISECONDS == unit) {
|
||||
|
||||
return connection.invoke(connection.getAsyncDedicatedConnection())
|
||||
.from(RedisSortedSetAsyncCommands::bzpopmax, preciseTimeout(timeout, unit), key)
|
||||
.from(RedisSortedSetAsyncCommands::bzpopmax, TimeoutUtils.toDoubleSeconds(timeout, unit), key)
|
||||
.get(it -> it.map(LettuceConverters::toTuple).getValueOrElse(null));
|
||||
}
|
||||
|
||||
@@ -914,8 +915,4 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
static double preciseTimeout(long val, TimeUnit unit) {
|
||||
return (double) unit.toMillis(val) / 1000.0D;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +256,6 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {
|
||||
/**
|
||||
* Removes and returns first {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return can be {@literal null}.
|
||||
* @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
|
||||
@@ -308,7 +307,6 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {
|
||||
/**
|
||||
* Removes and returns last {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return can be {@literal null}.
|
||||
* @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
|
||||
|
||||
@@ -196,6 +196,7 @@ public interface ListOperations<K, V> {
|
||||
final Direction direction;
|
||||
|
||||
MoveFrom(K key, Direction direction) {
|
||||
|
||||
this.key = key;
|
||||
this.direction = direction;
|
||||
}
|
||||
@@ -207,7 +208,6 @@ public interface ListOperations<K, V> {
|
||||
public static <K> MoveFrom<K> fromTail(K key) {
|
||||
return new MoveFrom<>(key, Direction.last());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,6 +223,7 @@ public interface ListOperations<K, V> {
|
||||
final Direction direction;
|
||||
|
||||
MoveTo(K key, Direction direction) {
|
||||
|
||||
this.key = key;
|
||||
this.direction = direction;
|
||||
}
|
||||
@@ -234,7 +235,6 @@ public interface ListOperations<K, V> {
|
||||
public static <K> MoveTo<K> toTail(K key) {
|
||||
return new MoveTo<>(key, Direction.last());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user