|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|