-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[DRAFT] Support sub second timeout for BRPOP & BLPOP via RedisListCommands. #2127
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution. I left a few comments that you might want to review. Note that some of the comments apply to repeated usage such as the checking for TimeUnit
.
Let us know if you have any further questions.
@@ -1233,13 +1235,15 @@ public long getCount() { | |||
class BPopCommand implements Command { | |||
|
|||
private final List<ByteBuffer> keys; | |||
private final Duration timeout; | |||
private final @Nullable Long timeout; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd like to keep Duration
as that is the more expressive API. TimeUnit
and timeout always require a tuple.
* @see #lPop(byte[]) | ||
*/ | ||
@Nullable | ||
List<byte[]> bLPop(int timeout, TimeUnit unit, byte[]... keys); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: @since 2.6
|
||
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); | ||
if (TimeUnit.MILLISECONDS == unit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that one could use MICROSECONDS
and NANOSECONDS
as units. Ideally, we add a utility method to TimeoutUtils
along the lines of supportsDoubleSeconds
or isSubSecondUnit
instead of repeating the same code to check the timeout across the code base.
@@ -351,7 +352,19 @@ | |||
Assert.notNull(command.getKeys(), "Keys must not be null!"); | |||
Assert.notNull(command.getDirection(), "Direction must not be null!"); | |||
|
|||
long timeout = command.getTimeout().get(ChronoUnit.SECONDS); | |||
|
|||
if (command.getTimeUnit() == TimeUnit.MILLISECONDS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See TimeoutUtils.hasMillis(Duration)
One last thing, please provide additional tests for sub-second timeouts via |
I got it, thanks for review |
see #2102