一个练手的小项目(二)——Redis集群
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