jhutchison commented on a change in pull request #5216:
URL: https://github.com/apache/geode/pull/5216#discussion_r436187466



##########
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;
+    }
+
+    if (optionalParametersStrings.contains("PX")) {
+      int index = optionalParametersStrings.indexOf("PX");

Review comment:
       done - thanks
   
   




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to