Skip to content

Conversation

@ringles
Copy link
Contributor

@ringles ringles commented Jul 22, 2021

Add support for the ZREVRANGEBYSCORE Redis comand.

@ringles ringles marked this pull request as ready for review July 23, 2021 16:39
@jdeppe-pivotal jdeppe-pivotal added the redis Issues related to the geode-for-redis module label Jul 24, 2021
Copy link
Contributor

@DonalEvans DonalEvans left a comment

Choose a reason for hiding this comment

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

This PR needs to add a test in AbstractHitsMissesIntegrationTest to confirm that stats are correctly updated. Also, I think it would be beneficial to wait for this PR to be merged and then rebase, since there's some code added there that would be useful to this PR.

return getRange(min, max, withScores, false);
}

List<byte[]> zrevrangebyscore(SortedSetRangeOptions rangeOptions, boolean withScores) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method should also be overridden in NullRedisSortedSet to return an empty list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, caught that earlier today!

Copy link
Contributor

Choose a reason for hiding this comment

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

Could this method also be moved down in the class to maintain the alphabetical ordering of the command methods? It should be between zrevrange() and zrevrank(). This same feedback applies to the methods in RedisSortedSetCommands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alphabetized.

Copy link
Contributor

@DonalEvans DonalEvans left a comment

Choose a reason for hiding this comment

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

Looks good, with the understanding that it'll be rebased and modified to make use of new methods once the ZRANGEBYLEX PR has been merged. I'll give it another look over once that's done for final approval.

return getRange(min, max, withScores, false);
}

List<byte[]> zrevrangebyscore(SortedSetRangeOptions rangeOptions, boolean withScores) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this method also be moved down in the class to maintain the alphabetical ordering of the command methods? It should be between zrevrange() and zrevrank(). This same feedback applies to the methods in RedisSortedSetCommands.

}

int startIndex = maxIndex - 1;
int endIndex = Math.min(count, maxIndex - minIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable is actually the expected number of elements to be returned, not the index of the maximum element. The code found in the addLimitToRange() method added as part of the ZRANGEBYLEX PR could be used here to simplify things and reduce code reuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using addLimitToRange() now (with some tweaks to handle reverse ranges).

long zcount(SortedSetScoreRangeOptions rangeOptions) {
AbstractOrderedSetEntry minEntry = new ScoreDummyOrderedSetEntry(rangeOptions.getMinimum(),
rangeOptions.isMinExclusive(), true);
AbstractOrderedSetEntry minEntry = new ScoreDummyOrderedSetEntry(rangeOptions.getStartRange(),
Copy link
Contributor

Choose a reason for hiding this comment

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

consider refactoring this code so it looks like:
long minIndex = getMinIndex(rangeOptions);
long maxIndex = getMaxIndex(rangeOptions);
I think we could use getMinIndex and getMaxIndex in a couple of places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't do it quite that way, but extracted a couple methods that indeed can be used in several places. Good catch; hope this is along the lines of your thinking...


Iterator<AbstractOrderedSetEntry> entryIterator =
scoreSet.getIndexRange(startIndex, endIndex, true);
List<byte[]> result = new ArrayList<>(initialCapacity > 0 ? initialCapacity : 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

if initialCapacity is <= 0 does that mean we will return an empty list? If so should we just have checked (up at line 414) if (initialCapacity <= 0) {return Collections.emptyList();}? Then this could just be new ArrayList<>(initialCapacity)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, per Donal we're using the addLimitToRange (with some tweaks now).

return (hasLimit && (count == 0 || offset < 0)) || minVsMax == 1
|| (minVsMax == 0 && (isMinExclusive || isMaxExclusive));
boolean isEmptyRange(boolean isRev) {
int startVsEnd = compareStartToEnd();
Copy link
Contributor

Choose a reason for hiding this comment

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

Much is now repeated between the if and then else.
I think this code would be clearer if you didn't try to do everything in one boolean expression. For example:
if (hasLimit && (count == 0 || offset < 0)) {
return true;
}
int startVsEnd = compareStartToEnd();
if (startVsEnd == 0 && (isStartExclusive || isEndExclusive)) {
return true;
}
if (isRev) {
return startVsEnd == -1;
} else {
return startVsEnd == 1;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted the code, and the leading comment to match the test order.

@ringles ringles dismissed DonalEvans’s stale review August 12, 2021 21:02

Changes addressed but not available to validate.

@ringles ringles merged commit 8d455b4 into apache:develop Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

redis Issues related to the geode-for-redis module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants