Jedis connects to redis cluster

public static void main(String[] args) throws IOException{
   Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
   jedisClusterNode.add(new HostAndPort("ip",7001));//添加对应机器的ip地址和端口号
   jedisClusterNode.add(new HostAndPort("ip",7002));
   jedisClusterNode.add(new HostAndPort("ip",7003));
   jedisClusterNode.add(new HostAndPort("ip",7004));
   jedisClusterNode.add(new HostAndPort("ip",7005));
   jedisClusterNode.add(new HostAndPort("ip",7006));
   JedisPoolConfig config = new JedisPoolConfig();
   config.setMaxTotal(100);//设置最大连接数
   config.setMaxIdle(10);//设置最大空闲连接
   JedisCluster jedisCluster = new JedisCluster(jedisClusterNode,5000,10,config);
   //jedisClusterNode 服务节点信息
   //5000 设置连接超时的最大时间
   //10 循环尝试连接次数
   //config jedis连接池配置

    // TODO codeing Redis Opreate


   jedisCluster.close();
}

Test some operations

System.out.println(jedisCluster.set("stu","xiaoming"));
System.out.println(jedisCluster.set("age","18"));
System.out.println(jedisCluster.get("stu"));
System.out.println(jedisCluster.get("age"));

write picture description here

Then go to the redis client to query: Query
write picture description here
at 7001 and get the value corresponding to age. Query stu
at 7001, indicating that stu is on the 7003 server

In fact, this is when the redis cluster cluster is written, the default is to poll according to the server

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325776068&siteId=291194637