You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/08/13 01:17:35 UTC

[GitHub] [druid] FrankChen021 commented on a change in pull request #10240: Redis cache extension enhancement

FrankChen021 commented on a change in pull request #10240:
URL: https://github.com/apache/druid/pull/10240#discussion_r469639143



##########
File path: extensions-contrib/redis-cache/src/main/java/org/apache/druid/client/cache/RedisCacheFactory.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.druid.client.cache;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.druid.java.util.common.IAE;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
+
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class RedisCacheFactory
+{
+  public static Cache create(final RedisCacheConfig config)
+  {
+    if (config.getCluster() != null && StringUtils.isNotBlank(config.getCluster().getNodes())) {
+
+      Set<HostAndPort> nodes = Arrays.stream(config.getCluster().getNodes().split(","))
+                                     .map(String::trim)
+                                     .filter(StringUtils::isNotBlank)
+                                     .map(host -> {
+                                       int index = host.indexOf(':');
+                                       if (index <= 0 || index == host.length()) {
+                                         throw new IAE("Invalid redis cluster configuration: %s", host);
+                                       }
+
+                                       int port;
+                                       try {
+                                         port = Integer.parseInt(host.substring(index + 1));
+                                       }
+                                       catch (NumberFormatException e) {
+                                         throw new IAE("Invalid redis cluster configuration: invalid port %s", host);
+                                       }
+                                       if (port <= 0 || port > 65535) {
+                                         throw new IAE("Invalid redis cluster configuration: invalid port %s", host);

Review comment:
       `host` here contains the host name and port. I think the variable name is a little bit ambiguous, it should be changed to `hostAndPort` to make it clear.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org