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 2021/09/08 17:51:01 UTC

[GitHub] [geode] DonalEvans commented on a change in pull request #6847: GEODE-9585: adding support for the KEYSLOT command

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



##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/KeyHashUtil.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.data;
+
+import static org.apache.geode.redis.internal.RegionProvider.REDIS_SLOTS;
+
+import org.apache.geode.redis.internal.executor.cluster.CRC16;
+
+/**
+ * Utility for parsing the hashtags in a redis key and computing the redis slot of the key.
+ */
+public class KeyHashUtil {
+
+  /**
+   * Compute the slot of a given redis key
+   *
+   * @return the slot, a value between 0 and 16K.
+   */
+  public static int slotForKey(byte[] value) {
+    int startHashtag = Integer.MAX_VALUE;
+    int endHashtag = 0;
+
+    for (int i = 0; i < value.length; i++) {
+      if (value[i] == '{' && startHashtag == Integer.MAX_VALUE) {

Review comment:
       In the `StringBytesGlossary` class, there's a comment (originally in the Coder class before the constants were pulled out into their own class) stating:
   > Do not use '' <-- java primitive chars. Redis uses `{@link Coder#CHARSET}` encoding so we should
   not risk java handling char to byte conversions, rather just hard code `{@link Coder#CHARSET}`
   chars as bytes
   Is this a concern here?




-- 
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-unsubscribe@geode.apache.org

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