Hisoka-X commented on code in PR #9869:
URL: https://github.com/apache/seatunnel/pull/9869#discussion_r2382545397


##########
seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/config/JedisWrapper.java:
##########
@@ -82,8 +93,65 @@ public List<String> zrange(final String key, final long 
start, final long stop)
         return jedisCluster.zrange(key, start, stop);
     }
 
+    @Override
+    public String info() {
+        Map<String, ConnectionPool> nodes = jedisCluster.getClusterNodes();
+        if (nodes.isEmpty()) {
+            throw new RedisConnectorException(
+                    GET_REDIS_INFO_ERROR, "No available nodes in cluster");
+        }
+
+        // Traverse all nodes and try to obtain the info
+        for (Map.Entry<String, Jedis> entry : jedisPoolMap.entrySet()) {
+            try {
+                Jedis jedis = entry.getValue();
+                return jedis.info();
+            } catch (Exception e) {
+                log.warn("Failed to get info from node: {}", entry.getKey(), 
e);
+            }
+        }
+
+        throw new RedisConnectorException(
+                GET_REDIS_INFO_ERROR, "Failed to get redis info from all node 
in cluster");
+    }
+
+    @Override
+    public String type(String key) {
+        return jedisCluster.type(key);
+    }
+
+    public Map<String, ConnectionPool> getClusterNodes() {
+        return jedisCluster.getClusterNodes();
+    }
+
+    @Override
+    public long expire(final String key, final long seconds) {
+        return jedisCluster.expire(key, seconds);
+    }
+
     @Override
     public void close() {
         jedisCluster.close();

Review Comment:
   we should close `JedisConnectionCache` too?



##########
docs/zh/connector-v2/sink/Redis.md:
##########
@@ -210,7 +223,7 @@ Redis {
 Redis {
   host = localhost
   port = 6379
-  key = "name:{name}"
+  key = "name:${name}"

Review Comment:
   I think we should do some special case for redis to make sure legacy 
behavior work fine too.



##########
seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/config/JedisWrapper.java:
##########
@@ -17,19 +17,30 @@
 
 package org.apache.seatunnel.connectors.seatunnel.redis.config;
 
+import 
org.apache.seatunnel.connectors.seatunnel.redis.exception.RedisConnectorException;
+import 
org.apache.seatunnel.connectors.seatunnel.redis.exception.RedisErrorCode;
+
 import lombok.NonNull;
+import lombok.extern.slf4j.Slf4j;
+import redis.clients.jedis.ConnectionPool;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.JedisCluster;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static 
org.apache.seatunnel.connectors.seatunnel.redis.exception.RedisErrorCode.GET_REDIS_INFO_ERROR;
+
+@Slf4j
 public class JedisWrapper extends Jedis {
     private final JedisCluster jedisCluster;
+    private final Map<String, Jedis> jedisPoolMap = new HashMap<>();
 
     public JedisWrapper(@NonNull JedisCluster jedisCluster) {
         this.jedisCluster = jedisCluster;
+        initJedisConnectionCache();

Review Comment:
   let's create connection with lazy mode. I think most time we should not use 
it.



##########
seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/config/JedisWrapper.java:
##########
@@ -82,6 +89,48 @@ public List<String> zrange(final String key, final long 
start, final long stop)
         return jedisCluster.zrange(key, start, stop);
     }
 
+    @Override
+    public String info() {

Review Comment:
   I got it. 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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to