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



##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/data/RedisList.java
##########
@@ -126,6 +127,25 @@ private int getArrayIndex(int listIndex) {
     return listIndex;
   }
 
+  /**
+   * @param elementToInsert element to insert into the set
+   * @param referenceElement element to insert next to
+   * @param before true if inserting before reference element, false if it is 
after
+   * @param region the region this instance is store in
+   * @param key the name of the list to add to
+   * @return the number of elements in the list after the element is inserted

Review comment:
       It would be good to include a mention in this comment that this method 
can also return -1 if the pivot element was not found.

##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/data/RedisList.java
##########
@@ -204,6 +229,32 @@ public int getDSFID() {
     return REDIS_LIST_ID;
   }
 
+  public synchronized int elementInsert(byte[] elementToInsert, byte[] 
referenceElement,
+      boolean before) {
+    int i = 0;
+    ListIterator<byte[]> iterator = elementList.listIterator();
+
+    while (iterator.hasNext()) {
+      if (Arrays.equals(iterator.next(), referenceElement)) {
+        if (!before) {

Review comment:
       Really small nitpick, but could this if statement be inverted, so that 
we have `if (before) {` at the top? I find it makes it easier to read if we can 
avoid negation in the conditions.

##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/data/RedisList.java
##########
@@ -126,6 +127,25 @@ private int getArrayIndex(int listIndex) {
     return listIndex;
   }
 
+  /**
+   * @param elementToInsert element to insert into the set
+   * @param referenceElement element to insert next to
+   * @param before true if inserting before reference element, false if it is 
after
+   * @param region the region this instance is store in
+   * @param key the name of the list to add to
+   * @return the number of elements in the list after the element is inserted
+   */
+  public int linsert(byte[] elementToInsert, byte[] referenceElement, boolean 
before,
+      Region<RedisKey, RedisData> region, RedisKey key) {
+    int index = elementInsert(elementToInsert, referenceElement, before);
+    if (index == -1) {
+      return index;
+    }
+    storeChanges(region, key, new InsertByteArray(elementToInsert, index));
+
+    return elementList.size();

Review comment:
       This method should be updated to use versioning in the Delta, similar to 
what was done for the APPEND command in GEODE-10108.

##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/commands/executor/list/LInsertExecutor.java
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.commands.executor.list;
+
+import java.util.List;
+
+import org.apache.geode.cache.Region;
+import org.apache.geode.redis.internal.RedisConstants;
+import org.apache.geode.redis.internal.commands.Command;
+import org.apache.geode.redis.internal.commands.executor.CommandExecutor;
+import org.apache.geode.redis.internal.commands.executor.RedisResponse;
+import org.apache.geode.redis.internal.data.RedisData;
+import org.apache.geode.redis.internal.data.RedisKey;
+import org.apache.geode.redis.internal.netty.Coder;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class LInsertExecutor implements CommandExecutor {
+
+  @Override
+  public RedisResponse executeCommand(Command command, ExecutionHandlerContext 
context) {
+    List<byte[]> commandElements = command.getProcessedCommand();
+
+    String direction = Coder.bytesToString(commandElements.get(2));
+    boolean before;
+    byte[] referenceElement = commandElements.get(3);
+    byte[] elementToInsert = commandElements.get(4);
+
+    if (direction.equalsIgnoreCase("before")) {
+      before = true;
+    } else if (direction.equalsIgnoreCase("after")) {

Review comment:
       Rather than creating a String here and doing `equalsIgnoreCase()` it 
would be more performant to add two new constants to `StringBytesGlossary`:
   ```
     // LInsertExecutor
     public static final byte[] BEFORE = stringToBytes("BEFORE");
     public static final byte[] AFTER = stringToBytes("AFTER");
   ```
   and compare against them using `Arrays.equals()` here in the executor:
   ```
       byte[] direction = toUpperCaseBytes(commandElements.get(2));
   
       if (Arrays.equals(direction, BEFORE)) {
         before = true;
       } else if (Arrays.equals(direction, AFTER)) {
         before = false;
   ```




-- 
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: notifications-unsubscr...@geode.apache.org

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


Reply via email to