DonalEvans commented on a change in pull request #6715:
URL: https://github.com/apache/geode/pull/6715#discussion_r679394365



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -310,18 +311,62 @@ long zcount(SortedSetRangeOptions rangeOptions) {
     return getRange(min, max, withScores, false);
   }
 
+  List<byte[]> zrevrangebyscore(SortedSetRangeOptions rangeOptions, boolean 
withScores) {

Review comment:
       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`.

##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -310,18 +311,66 @@ long zcount(SortedSetRangeOptions rangeOptions) {
     return getRange(min, max, withScores, false);
   }
 
+  List<byte[]> zrevrangebyscore(SortedSetRangeOptions rangeOptions, boolean 
withScores) {
+    AbstractOrderedSetEntry maxEntry =
+        new DummyOrderedSetEntry(rangeOptions.getStartDouble(), 
rangeOptions.isStartExclusive(),
+            false);
+    int maxIndex = scoreSet.indexOf(maxEntry);
+
+    AbstractOrderedSetEntry minEntry =
+        new DummyOrderedSetEntry(rangeOptions.getEndDouble(), 
rangeOptions.isEndExclusive(), true);
+    int minIndex = scoreSet.indexOf(minEntry);
+    if (minIndex > getSortedSetSize()) {
+      return Collections.emptyList();
+    }
+
+    if (minIndex == maxIndex) {
+      return Collections.emptyList();
+    }
+
+    // Okay, if we make it this far there's a potential range of things to 
return.
+    int count = Integer.MAX_VALUE;
+    if (rangeOptions.hasLimit()) {
+      count = rangeOptions.getCount();
+      maxIndex -= rangeOptions.getOffset();
+      if (maxIndex < 0) {
+        return Collections.emptyList();
+      }
+    }
+
+    int startIndex = maxIndex - 1;
+    int endIndex = Math.min(count, maxIndex - minIndex);

Review comment:
       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.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to