You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2020/06/05 17:18:22 UTC

[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #5216: Refactor set executor

jdeppe-pivotal commented on a change in pull request #5216:
URL: https://github.com/apache/geode/pull/5216#discussion_r436056100



##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/executor/string/SetExecutor.java
##########
@@ -68,72 +75,141 @@ private ByteArrayWrapper getValueToSet(List<byte[]> commandElems) {
     return new ByteArrayWrapper(value);
   }
 
+  private SetOptions parseOptionalParameters(List<byte[]> optionalParameterBytes)
+      throws IllegalArgumentException {
 
-  private SetOptions parseCommandElems(List<byte[]> commandElems) throws IllegalArgumentException {
     boolean keepTTL = false;
     SetOptions.Exists existsOption = SetOptions.Exists.NONE;
     long expiration = 0L;
 
-    for (int i = 3; i < commandElems.size(); i++) {
-      String current_arg = Coder.bytesToString(commandElems.get(i)).toUpperCase();
-      switch (current_arg) {
-        case "KEEPTTL":
-          keepTTL = true;
-          break;
-        case "EX":
-          if (expiration != 0) {
-            throw new IllegalArgumentException(ERROR_SYNTAX);
-          }
-          i++;
-          expiration = parseExpirationTime(i, commandElems);
-          expiration = SECONDS.toMillis(expiration);
-          break;
-        case "PX":
-          if (expiration != 0) {
-            throw new IllegalArgumentException(ERROR_SYNTAX);
-          }
-          i++;
-          expiration = parseExpirationTime(i, commandElems);
-          break;
-        case "NX":
-          if (existsOption != SetOptions.Exists.NONE) {
-            throw new IllegalArgumentException(ERROR_SYNTAX);
-          }
-          existsOption = SetOptions.Exists.NX;
-          break;
-        case "XX":
-          if (existsOption != SetOptions.Exists.NONE) {
-            throw new IllegalArgumentException(ERROR_SYNTAX);
-          }
-          existsOption = SetOptions.Exists.XX;
-          break;
-        default:
-          throw new IllegalArgumentException(ERROR_SYNTAX);
+    List<String> optionalParametersStrings =
+        optionalParameterBytes.stream()
+            .map(item -> Coder.bytesToString(item).toUpperCase())
+            .collect(Collectors.toList());
+
+    throwExceptionIfUnknownParameter(optionalParametersStrings);
+    throwExceptionIfIncompatableParamaterOptions(optionalParametersStrings);
+
+    if (optionalParametersStrings.contains("KEEPTL")) {
+      keepTTL = true;
+    }

Review comment:
       This could be simplified to:
   ```
   keepTTL = optionalParametersStrings.contains("KEEPTL");
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org