Skip to content

[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

Closed
wants to merge 8 commits into from

Conversation

ihaohong
Copy link
Contributor

@ihaohong ihaohong commented Jul 20, 2021

see #2102

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 20, 2021
Copy link
Member

@mp911de mp911de left a 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;
Copy link
Member

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);
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See TimeoutUtils.hasMillis(Duration)

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 21, 2021
@mp911de
Copy link
Member

mp911de commented Jul 21, 2021

One last thing, please provide additional tests for sub-second timeouts via AbstractConnectionIntegrationTests and LettuceReactiveListCommandIntegrationTests.

@ihaohong
Copy link
Contributor Author

I got it, thanks for review

@ihaohong ihaohong changed the title Support sub second timeout for BRPOP & BLPOP via RedisListCommands. [DRAFT] Support sub second timeout for BRPOP & BLPOP via RedisListCommands. Jul 27, 2021
@ihaohong ihaohong closed this Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants