一. 依赖
redis.clients
jedis
3.7.0
com.redislabs
jrebloom
1.2.0
org.redisson
redisson
3.17.5
io.lettuce
lettuce-core
6.2.0.RELEASE
二 . 操作类
Set nodes = new HashSet<>();
nodes.add(new HostAndPort("1.12.235.192", 7016));
nodes.add(new HostAndPort("1.12.235.192", 7017));
nodes.add(new HostAndPort("1.12.235.192", 7018));
nodes.add(new HostAndPort("1.12.235.192", 7019));
nodes.add(new HostAndPort("1.12.235.192", 7020));
nodes.add(new HostAndPort("1.12.235.192", 7021));
JedisPoolConfig config = new JedisPoolConfig();
//连接池最大连接数
config.setMaxIdle(300);
//最大连接数
config.setMaxTotal(1000);
//连接最大等待时间,若是-1没有限制
config.setMaxWaitMillis(30000);
//在空闲时检查有效性
config.setTestOnBorrow(true);
JedisCluster cluster = new JedisCluster(nodes,15000,15000, 5, "123", config);
String set = cluster.set("k1", "v1");
System.out.println(set);
String k1 = cluster.get("k1");
System.out.println(k1);
三.application配置
spring.redis.host=1.12.235.192
spring.redis.password=123
spring.redis.port=7016
server.port=8080