kobe6258 hai 2 semanas
pai
achega
8c11e4ea7e

+ 17 - 11
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/config/RedissonConfig.java

@@ -9,28 +9,34 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import java.util.Arrays;
+import java.util.List;
+
 @Configuration
 public class RedissonConfig {
 
-    @Value("${spring.redis.host}")
-    private String host;
-
-    @Value("${spring.redis.password}")
+    @Value("${redisson.address}")
+    private String address;
+    @Value("${redisson.password}")
     private String password;
 
-    @Value("${spring.redis.port}")
-    private String port;
-
-    @Value("${spring.redis.database}")
+    @Value("${redisson.database}")
     private int database;
 
     @Bean
     public RedissonClient redissonClient() {
         Config config = new Config();
-        if (StringUtils.isNotBlank(password)) {
-            config.useSingleServer().setAddress("redis://" + host + ":" + port).setPassword(password).setDatabase(database);
+        List<String> hosts = Arrays.asList(address.split(";"));
+        if (hosts.size() == 1) {
+            config.useSingleServer().setAddress("redis://"+address).setDatabase(database);
+            if (StringUtils.isNotBlank(password)) {
+                config.useSingleServer().setAddress("redis://"+address).setPassword(password).setDatabase(database);
+            }
         } else {
-            config.useSingleServer().setAddress("redis://" + host + ":" + port).setDatabase(database);
+            if (StringUtils.isNotBlank(password)) {
+                config.useClusterServers().setPassword(password);
+            }
+            hosts.forEach(h -> config.useClusterServers().addNodeAddress("redis://"+h));
         }
         return Redisson.create(config);
     }