1 4 роки тому
батько
коміт
de4e846e90

+ 6 - 0
common/fire-common/pom.xml

@@ -18,6 +18,12 @@
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>com.blue</groupId>
             <artifactId>fire-dto</artifactId>

+ 45 - 0
common/fire-common/src/main/java/com.fire.common/esdemo/config/RedisConfig.java

@@ -0,0 +1,45 @@
+package com.fire.common.esdemo.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author: admin
+ * @Description:
+ * @date: 2021-05-09 20:50
+ * @Modified By:
+ */
+@Configuration
+@Slf4j
+public class RedisConfig {
+
+    @Value("${spring.redis.cluster.nodes}")
+    private String clusterNodes;
+
+    @Bean
+    public JedisCluster getJedisCluster() {
+        Set<HostAndPort> nodes = new HashSet<>();
+
+        try {
+            String[] clusNodes = clusterNodes.split(",");
+
+            for (String clusNode : clusNodes) {
+                String[] hostAndPort = clusNode.split(":");
+                nodes.add(new HostAndPort(hostAndPort[0], Integer.parseInt(hostAndPort[1])));
+            }
+
+        } catch (Exception e) {
+            log.info("Redis服务异常!");
+            e.printStackTrace();
+        }
+        return new JedisCluster(nodes,10000);
+    }
+
+}

+ 5 - 1
modules/admin/src/main/resources/bootstrap.yml

@@ -26,7 +26,11 @@ spring:
       max-lifetime: 1600000
       connection-timeout: 30000
       pool-name: DatebookHikariCP
-
+  redis:
+    cluster:
+      nodes: 192.168.101.100:7001,192.168.101.100:7002,192.168.101.100:7003,192.168.101.101:7004,192.168.101.101:7005,192.168.101.101:7006,192.168.101.102:7007,192.168.101.102:7008
+#    host: 192.168.101.100
+#    port: 11670
 jwt:
   header: Authorization
   tokenHead: Bearer