RedisConfig.java:
package com.tsvv.config; import java.util.HashSet; import java.util.Set; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.JedisCluster; //標識配置類 @Configuration @PropertySource("classpath:/properties/redis.properties") public class RedisConfig { @Value("${redis.clusterNodes}") private String nodes; @Bean public JedisCluster jedisCluster() { Set<HostAndPort> nodeSet=new HashSet<>(); String[] arrayNodes=nodes.split(","); for (String node : arrayNodes) { String host=node.split(":")[0]; int port=Integer.parseInt(node.split(":")[1]); nodeSet.add(new HostAndPort(host, port)); } return new JedisCluster(nodeSet); } }
redis.properties:
#最小空閒數 redis.minIdle=100 #最大空閒數 redis.maxIdle=300 #最大鏈接數 redis.maxTotal=1000 #定義redis節點信息 redis.clusterNodes=192.168.6.129:7000,192.168.6.129:7001,192.168.6.129:7002,192.168.6.129:7003,192.168.6.129:7004,192.168.6.129:7005