我使用虚拟机搭建了一个redis集群 分别对应了7001 7002 7003 7004 7005 7006端口 ,虚拟机设置的ip为192.168.242.128。我的主机ip地址为10.11.21.58 现在我将虚拟机设置了一个主机的映射端口为8888
我使用如下代码 连接不上redis集群 请大神指教
public class MyJedisCluster {
@Test
public void linkRedisCluster(){
//创建集群配置
JedisPoolConfig conf = new JedisPoolConfig();
//设置最大连接数
conf.setMaxTotal(50);
conf.setMaxIdle(2);
Set<HostAndPort> nodes = new HashSet<HostAndPort>();
nodes.add(new HostAndPort("10.11.21.58", 7001));
nodes.add(new HostAndPort("10.11.21.58", 7002));
nodes.add(new HostAndPort("10.11.21.58", 7003));
nodes.add(new HostAndPort("10.11.21.58", 7004));
nodes.add(new HostAndPort("10.11.21.58", 7005));
nodes.add(new HostAndPort("10.11.21.58", 7006));
//创建Jedis集群对象
JedisCluster jedisCluster = new JedisCluster(nodes,conf);
//Set<String> hkeys = jedisCluster.hkeys("*");
//使用集群对象设置值
jedisCluster.set("money1", "180");
//使用集群对象获取值
String money1 = jedisCluster.get("money1");
System.out.println(money1);