ringles commented on a change in pull request #6700:
URL: https://github.com/apache/geode/pull/6700#discussion_r671327733



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -307,6 +308,57 @@ long zcount(SortedSetRangeOptions rangeOptions) {
     return getRange(min, max, withScores, false);
   }
 
+
+  List<byte[]> zrangebyscore(SortedSetRangeOptions rangeOptions, boolean 
withScores) {
+    List<byte[]> result = new ArrayList<>();
+    AbstractOrderedSetEntry minEntry =
+        new DummyOrderedSetEntry(rangeOptions.getMinDouble(), 
rangeOptions.isMinExclusive(), true);
+    long minIndex = scoreSet.indexOf(minEntry);

Review comment:
       They're typed as long because they're essentially the same code as in 
ZCOUNT. But it makes more sense for them to be int here, as you say.

##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSetCommandsFunctionExecutor.java
##########
@@ -62,6 +62,13 @@ public long zcount(RedisKey key, SortedSetRangeOptions 
rangeOptions) {
         () -> getRedisSortedSet(key, true).zrange(min, max, withScores));
   }
 
+  @Override
+  public List<byte[]> zrangebyscore(RedisKey key, SortedSetRangeOptions 
rangeOptions,
+      boolean withScores) {
+    return stripedExecute(key,
+        () -> getRedisSortedSet(key, true).zrangebyscore(rangeOptions, 
withScores));

Review comment:
       I see ZRANGE calling it with true. In general, operations that read data 
update stats, operations that change data do not. So zadd, zrem, zincrby change 
data and therefore don't update stats.

##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/ZRangeByScoreExecutor.java
##########
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.redis.internal.executor.sortedset;
+
+import static 
org.apache.geode.redis.internal.RedisConstants.ERROR_MIN_MAX_NOT_A_FLOAT;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
+import static org.apache.geode.redis.internal.netty.Coder.bytesToLong;
+import static 
org.apache.geode.redis.internal.netty.Coder.equalsIgnoreCaseBytes;
+import static org.apache.geode.redis.internal.netty.Coder.narrowLongToInt;
+import static 
org.apache.geode.redis.internal.netty.StringBytesGlossary.bRADISH_LIMIT;
+import static 
org.apache.geode.redis.internal.netty.StringBytesGlossary.bRADISH_WITHSCORES;
+
+import java.util.List;
+
+import org.apache.geode.redis.internal.executor.AbstractExecutor;
+import org.apache.geode.redis.internal.executor.RedisResponse;
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class ZRangeByScoreExecutor extends AbstractExecutor {
+  @Override
+  public RedisResponse executeCommand(Command command, ExecutionHandlerContext 
context) {
+    RedisSortedSetCommands redisSortedSetCommands = 
context.getSortedSetCommands();
+
+    List<byte[]> commandElements = command.getProcessedCommand();
+
+    SortedSetRangeOptions rangeOptions;
+    boolean withScores = false;
+
+    try {
+      byte[] minBytes = commandElements.get(2);
+      byte[] maxBytes = commandElements.get(3);
+      rangeOptions = new SortedSetRangeOptions(minBytes, maxBytes);
+    } catch (NumberFormatException ex) {
+      return RedisResponse.error(ERROR_MIN_MAX_NOT_A_FLOAT);
+    }
+
+    if (commandElements.size() >= 5) {
+      int currentCommandElement = 4;
+      while (currentCommandElement < commandElements.size()) {
+        try {
+          if (equalsIgnoreCaseBytes(commandElements.get(currentCommandElement),
+              bRADISH_WITHSCORES)) {
+            withScores = true;
+            currentCommandElement++;
+          } else {
+            parseLimitArguments(rangeOptions, commandElements, 
currentCommandElement);
+            currentCommandElement += 3;
+          }
+        } catch (NumberFormatException ex) {
+          return RedisResponse.error(ERROR_NOT_INTEGER);
+        } catch (Exception e) {
+          return RedisResponse.error(ERROR_MIN_MAX_NOT_A_FLOAT);
+        }
+      }
+    }
+
+    // If the range is empty (min > max or min == max and both are exclusive), 
or
+    // limit specified but count is zero, return early
+    if ((rangeOptions.hasLimit() && (rangeOptions.getCount() == 0 || 
rangeOptions.getOffset() < 0))
+        ||
+        rangeOptions.getMinDouble() > rangeOptions.getMaxDouble() ||
+        (rangeOptions.getMinDouble() == rangeOptions.getMaxDouble())
+            && rangeOptions.isMinExclusive() && rangeOptions.isMaxExclusive()) 
{
+      return RedisResponse.emptyArray();
+    }
+
+    List<byte[]> result =
+        redisSortedSetCommands.zrangebyscore(command.getKey(), rangeOptions, 
withScores);
+
+    return RedisResponse.array(result);
+  }
+
+  void parseLimitArguments(SortedSetRangeOptions rangeOptions, List<byte[]> 
commandElements,
+      int commandIndex)
+      throws Exception {
+    int offset;
+    int count;
+    if (equalsIgnoreCaseBytes(commandElements.get(commandIndex), 
bRADISH_LIMIT)) {
+      offset = narrowLongToInt(bytesToLong(commandElements.get(commandIndex + 
1)));
+      count = narrowLongToInt(bytesToLong(commandElements.get(commandIndex + 
2)));
+      if (count < 0) {
+        count = Integer.MAX_VALUE;
+      }
+    } else {
+      throw new Exception();

Review comment:
       IllegalArgumentException seems to fit. Done.




-- 
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