Skip to content

Switch timeouts from int/long to double. #3189

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.x-GH-2102-SNAPSHOT</version>

<name>Spring Data Redis</name>
<description>Spring Data module for Redis</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,17 @@ public void bgReWriteAof() {
}

@Override
public List<byte[]> bLPop(int timeout, byte[]... keys) {
public List<byte[]> bLPop(double timeout, byte[]... keys) {
return convertAndReturn(delegate.bLPop(timeout, keys), Converters.identityConverter());
}

@Override
public List<byte[]> bRPop(int timeout, byte[]... keys) {
public List<byte[]> bRPop(double timeout, byte[]... keys) {
return convertAndReturn(delegate.bRPop(timeout, keys), Converters.identityConverter());
}

@Override
public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) {
public byte[] bRPopLPush(double timeout, byte[] srcKey, byte[] dstKey) {
return convertAndReturn(delegate.bRPopLPush(timeout, srcKey, dstKey), Converters.identityConverter());
}

Expand Down Expand Up @@ -1421,17 +1421,17 @@ public Long append(String key, String value) {
}

@Override
public List<String> bLPop(int timeout, String... keys) {
public List<String> bLPop(double timeout, String... keys) {
return convertAndReturn(delegate.bLPop(timeout, serializeMulti(keys)), byteListToStringList);
}

@Override
public List<String> bRPop(int timeout, String... keys) {
public List<String> bRPop(double timeout, String... keys) {
return convertAndReturn(delegate.bRPop(timeout, serializeMulti(keys)), byteListToStringList);
}

@Override
public String bRPopLPush(int timeout, String srcKey, String dstKey) {
public String bRPopLPush(double timeout, String srcKey, String dstKey) {
return convertAndReturn(delegate.bRPopLPush(timeout, serialize(srcKey), serialize(dstKey)), bytesToString);
}

Expand Down Expand Up @@ -2009,12 +2009,12 @@ public Long zLexCount(byte[] key, org.springframework.data.domain.Range<byte[]>
}

@Override
public @Nullable Tuple bZPopMin(byte[] key, long timeout, TimeUnit unit) {
public @Nullable Tuple bZPopMin(byte[] key, double timeout, TimeUnit unit) {
return delegate.bZPopMin(key, timeout, unit);
}

@Override
public @Nullable StringTuple bZPopMin(String key, long timeout, TimeUnit unit) {
public @Nullable StringTuple bZPopMin(String key, double timeout, TimeUnit unit) {
return convertAndReturn(delegate.bZPopMin(serialize(key), timeout, unit), tupleConverter);
}

Expand All @@ -2039,12 +2039,12 @@ public Long zLexCount(byte[] key, org.springframework.data.domain.Range<byte[]>
}

@Override
public @Nullable Tuple bZPopMax(byte[] key, long timeout, TimeUnit unit) {
public @Nullable Tuple bZPopMax(byte[] key, double timeout, TimeUnit unit) {
return delegate.bZPopMax(key, timeout, unit);
}

@Override
public @Nullable StringTuple bZPopMax(String key, long timeout, TimeUnit unit) {
public @Nullable StringTuple bZPopMax(String key, double timeout, TimeUnit unit) {
return convertAndReturn(delegate.bZPopMax(serialize(key), timeout, unit), tupleConverter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,14 @@ default List<byte[]> rPop(byte[] key, long count) {
/** @deprecated in favor of {@link RedisConnection#listCommands()}}. */
@Override
@Deprecated
default List<byte[]> bLPop(int timeout, byte[]... keys) {
default List<byte[]> bLPop(double timeout, byte[]... keys) {
return listCommands().bLPop(timeout, keys);
}

/** @deprecated in favor of {@link RedisConnection#listCommands()}}. */
@Override
@Deprecated
default List<byte[]> bRPop(int timeout, byte[]... keys) {
default List<byte[]> bRPop(double timeout, byte[]... keys) {
return listCommands().bRPop(timeout, keys);
}

Expand All @@ -842,7 +842,7 @@ default byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
/** @deprecated in favor of {@link RedisConnection#listCommands()}}. */
@Override
@Deprecated
default byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) {
default byte[] bRPopLPush(double timeout, byte[] srcKey, byte[] dstKey) {
return listCommands().bRPopLPush(timeout, srcKey, dstKey);
}

Expand Down Expand Up @@ -1028,7 +1028,7 @@ default Set<Tuple> zPopMin(byte[] key, long count) {
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Tuple bZPopMin(byte[] key, long timeout, TimeUnit unit) {
default Tuple bZPopMin(byte[] key, double timeout, TimeUnit unit) {
return zSetCommands().bZPopMin(key, timeout, unit);
}

Expand All @@ -1049,7 +1049,7 @@ default Set<Tuple> zPopMax(byte[] key, long count) {
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Tuple bZPopMax(byte[] key, long timeout, TimeUnit unit) {
default Tuple bZPopMax(byte[] key, double timeout, TimeUnit unit) {
return zSetCommands().bZPopMax(key, timeout, unit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ private HashExpireCommand(@Nullable ByteBuffer key, List<ByteBuffer> fields, Exp
* @param unit the unit of measure for the {@code timeout}.
* @return new instance of {@link HashExpireCommand}.
*/
public static HashExpireCommand expire(List<ByteBuffer> fields, long timeout, TimeUnit unit) {
public static HashExpireCommand expire(List<ByteBuffer> fields, double timeout, TimeUnit unit) {

Assert.notNull(fields, "Field must not be null");
return expire(fields, Expiration.from(timeout, unit));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1744,11 +1744,11 @@ class BZPopCommand extends KeyCommand {
private final PopDirection direction;

private final @Nullable TimeUnit timeUnit;
private final @Nullable Long timeout;
private final @Nullable Double timeout;

private final long count;

private BZPopCommand(@Nullable ByteBuffer key, @Nullable Long timeout, @Nullable TimeUnit timeUnit, long count,
private BZPopCommand(@Nullable ByteBuffer key, @Nullable Double timeout, @Nullable TimeUnit timeUnit, long count,
PopDirection direction) {

super(key);
Expand Down Expand Up @@ -1809,7 +1809,7 @@ public BZPopCommand blockingFor(Duration timeout) {

Assert.notNull(timeout, "Timeout must not be null");

return blockingFor(timeout.toMillis(), TimeUnit.MILLISECONDS);
return blockingFor((double)timeout.toMillis(), TimeUnit.MILLISECONDS);
}

/**
Expand All @@ -1819,7 +1819,7 @@ public BZPopCommand blockingFor(Duration timeout) {
* @param timeUnit must not be {@literal null}.
* @return a new {@link BZPopCommand} with {@link Duration timeout} applied.
*/
public BZPopCommand blockingFor(long timeout, TimeUnit timeUnit) {
public BZPopCommand blockingFor(Double timeout, TimeUnit timeUnit) {

Assert.notNull(timeUnit, "TimeUnit must not be null");

Expand All @@ -1833,7 +1833,7 @@ public PopDirection getDirection() {
return direction;
}

public @Nullable Long getTimeout() {
public @Nullable Double getTimeout() {
return timeout;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ byte[] bLMove(byte @NonNull [] sourceKey, byte @NonNull [] destinationKey, @NonN
* @see #lPop(byte[])
*/
@Nullable
List<byte @NonNull []> bLPop(int timeout, byte @NonNull [] @NonNull... keys);
List<byte @NonNull []> bLPop(double timeout, byte @NonNull [] @NonNull... keys);

/**
* Removes and returns last element from lists stored at {@code keys}. <br>
Expand All @@ -314,7 +314,7 @@ byte[] bLMove(byte @NonNull [] sourceKey, byte @NonNull [] destinationKey, @NonN
* @see <a href="https://redis.io/commands/brpop">Redis Documentation: BRPOP</a>
* @see #rPop(byte[])
*/
List<byte @NonNull []> bRPop(int timeout, byte @NonNull [] @NonNull... keys);
List<byte @NonNull []> bRPop(double timeout, byte @NonNull [] @NonNull... keys);

/**
* Remove the last element from list at {@code srcKey}, append it to {@code dstKey} and return its value.
Expand All @@ -337,5 +337,5 @@ byte[] bLMove(byte @NonNull [] sourceKey, byte @NonNull [] destinationKey, @NonN
* @see <a href="https://redis.io/commands/brpoplpush">Redis Documentation: BRPOPLPUSH</a>
* @see #rPopLPush(byte[], byte[])
*/
byte[] bRPopLPush(int timeout, byte @NonNull [] srcKey, byte @NonNull [] dstKey);
byte[] bRPopLPush(double timeout, byte @NonNull [] srcKey, byte @NonNull [] dstKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,6 @@ default Long time() {
* @see <a href="https://redis.io/commands/migrate">Redis Documentation: MIGRATE</a>
*/
void migrate(byte @NonNull [] key, @NonNull RedisNode target, int dbIndex, @Nullable MigrateOption option,
long timeout);
long timeout);

}
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ default Long zCount(byte @NonNull [] key, double min, double max) {
* @see <a href="https://redis.io/commands/bzpopmin">Redis Documentation: BZPOPMIN</a>
* @since 2.6
*/
Tuple bZPopMin(byte @NonNull [] key, long timeout, @NonNull TimeUnit unit);
Tuple bZPopMin(byte @NonNull [] key, double timeout, @NonNull TimeUnit unit);

/**
* Remove and return the value with its score having the highest score from sorted set at {@code key}.
Expand Down Expand Up @@ -888,7 +888,7 @@ default Long zCount(byte @NonNull [] key, double min, double max) {
* @see <a href="https://redis.io/commands/bzpopmax">Redis Documentation: BZPOPMAX</a>
* @since 2.6
*/
Tuple bZPopMax(byte @NonNull [] key, long timeout, @NonNull TimeUnit unit);
Tuple bZPopMax(byte @NonNull [] key, double timeout, @NonNull TimeUnit unit);

/**
* Get the size of sorted set with {@code key}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,9 +1013,9 @@ String bLMove(@NonNull String sourceKey, @NonNull String destinationKey, @NonNul
* @param keys must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/blpop">Redis Documentation: BLPOP</a>
* @see RedisListCommands#bLPop(int, byte[]...)
* @see RedisListCommands#bLPop(double, byte[]...)
*/
List<String> bLPop(int timeout, @NonNull String @NonNull... keys);
List<String> bLPop(double timeout, @NonNull String @NonNull... keys);

/**
* Removes and returns last element from lists stored at {@code keys} (see: {@link #rPop(byte[])}). <br>
Expand All @@ -1025,9 +1025,9 @@ String bLMove(@NonNull String sourceKey, @NonNull String destinationKey, @NonNul
* @param keys must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/brpop">Redis Documentation: BRPOP</a>
* @see RedisListCommands#bRPop(int, byte[]...)
* @see RedisListCommands#bRPop(double, byte[]...)
*/
List<String> bRPop(int timeout, @NonNull String @NonNull... keys);
List<String> bRPop(double timeout, @NonNull String @NonNull... keys);

/**
* Remove the last element from list at {@code srcKey}, append it to {@code dstKey} and return its value.
Expand All @@ -1050,9 +1050,9 @@ String bLMove(@NonNull String sourceKey, @NonNull String destinationKey, @NonNul
* @param dstKey must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/brpoplpush">Redis Documentation: BRPOPLPUSH</a>
* @see RedisListCommands#bRPopLPush(int, byte[], byte[])
* @see RedisListCommands#bRPopLPush(double, byte[], byte[])
*/
String bRPopLPush(int timeout, @NonNull String srcKey, @NonNull String dstKey);
String bRPopLPush(double timeout, @NonNull String srcKey, @NonNull String dstKey);

// -------------------------------------------------------------------------
// Methods dealing with Redis Sets
Expand Down Expand Up @@ -1616,7 +1616,7 @@ String bLMove(@NonNull String sourceKey, @NonNull String destinationKey, @NonNul
* @see <a href="https://redis.io/commands/bzpopmin">Redis Documentation: BZPOPMIN</a>
* @since 2.6
*/
StringTuple bZPopMin(@NonNull String key, long timeout, @NonNull TimeUnit unit);
StringTuple bZPopMin(@NonNull String key, double timeout, @NonNull TimeUnit unit);

/**
* Remove and return the value with its score having the highest score from sorted set at {@code key}.
Expand Down Expand Up @@ -1650,7 +1650,7 @@ String bLMove(@NonNull String sourceKey, @NonNull String destinationKey, @NonNul
* @see <a href="https://redis.io/commands/bzpopmax">Redis Documentation: BZPOPMAX</a>
* @since 2.6
*/
StringTuple bZPopMax(@NonNull String key, long timeout, @NonNull TimeUnit unit);
StringTuple bZPopMax(@NonNull String key, double timeout, @NonNull TimeUnit unit);

/**
* Get the size of sorted set with {@code key}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,43 +294,43 @@ public byte[] rPop(byte[] key) {
}

@Override
public List<byte @NonNull []> bLPop(int timeout, byte @NonNull [] @NonNull... keys) {
public List<byte @NonNull []> bLPop(double timeout, byte @NonNull [] @NonNull... keys) {

Assert.notNull(keys, "Key must not be null");
Assert.noNullElements(keys, "Keys must not contain null elements");

if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
try {
return connection.getCluster().blpop(timeout, keys);
return JedisConverters.kvToList(connection.getCluster().blpop(timeout, keys));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}

return connection.getClusterCommandExecutor()
.executeMultiKeyCommand(
(JedisMultiKeyClusterCommandCallback<List<byte[]>>) (client, key) -> client.blpop(timeout, key),
(JedisMultiKeyClusterCommandCallback<List<byte[]>>) (client, key) -> JedisConverters.kvToList(client.blpop(timeout, key)),
Arrays.asList(keys))
.getFirstNonNullNotEmptyOrDefault(Collections.<byte[]> emptyList());
}

@Override
public List<byte @NonNull []> bRPop(int timeout, byte @NonNull [] @NonNull... keys) {
public List<byte @NonNull []> bRPop(double timeout, byte @NonNull [] @NonNull... keys) {

Assert.notNull(keys, "Key must not be null");
Assert.noNullElements(keys, "Keys must not contain null elements");

if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
try {
return connection.getCluster().brpop(timeout, keys);
return JedisConverters.kvToList(connection.getCluster().brpop(timeout, keys));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}

return connection.getClusterCommandExecutor()
.executeMultiKeyCommand(
(JedisMultiKeyClusterCommandCallback<List<byte[]>>) (client, key) -> client.brpop(timeout, key),
(JedisMultiKeyClusterCommandCallback<List<byte[]>>) (client, key) -> JedisConverters.kvToList(client.brpop(timeout, key)),
Arrays.asList(keys))
.getFirstNonNullNotEmptyOrDefault(Collections.<byte[]> emptyList());
}
Expand All @@ -355,14 +355,14 @@ public byte[] rPopLPush(byte @NonNull [] srcKey, byte @NonNull [] dstKey) {
}

@Override
public byte[] bRPopLPush(int timeout, byte @NonNull [] srcKey, byte @NonNull [] dstKey) {
public byte[] bRPopLPush(double timeout, byte @NonNull [] srcKey, byte @NonNull [] dstKey) {

Assert.notNull(srcKey, "Source key must not be null");
Assert.notNull(dstKey, "Destination key must not be null");

if (ClusterSlotHashUtil.isSameSlotForAllKeys(srcKey, dstKey)) {
try {
return connection.getCluster().brpoplpush(srcKey, dstKey, timeout);
return connection.getCluster().brpoplpush(srcKey, dstKey, Double.valueOf(timeout).intValue());
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ public Set<Tuple> zPopMin(byte @NonNull [] key, long count) {
}

@Override
public Tuple bZPopMin(byte @NonNull [] key, long timeout, @NonNull TimeUnit unit) {
public Tuple bZPopMin(byte @NonNull [] key, double timeout, @NonNull TimeUnit unit) {

Assert.notNull(key, "Key must not be null");
Assert.notNull(unit, "TimeUnit must not be null");

try {
return toTuple(connection.getCluster().bzpopmin(JedisConverters.toSeconds(timeout, unit), key));
return toTuple(connection.getCluster().bzpopmin(timeout, key));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
Expand Down Expand Up @@ -387,13 +387,13 @@ public Set<Tuple> zPopMax(byte @NonNull [] key, long count) {
}

@Override
public Tuple bZPopMax(byte @NonNull [] key, long timeout, @NonNull TimeUnit unit) {
public Tuple bZPopMax(byte @NonNull [] key, double timeout, @NonNull TimeUnit unit) {

Assert.notNull(key, "Key must not be null");
Assert.notNull(unit, "TimeUnit must not be null");

try {
return toTuple(connection.getCluster().bzpopmax(JedisConverters.toSeconds(timeout, unit), key));
return toTuple(connection.getCluster().bzpopmax(timeout, key));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
Expand Down
Loading