Map<String, JedisPool> map = jc.getClusterNodes(); for (Map.Entry<String, JedisPool> e : map.entrySet()) { System.out.println(e.getKey()); System.out.println("==================="); }
}
运行时报错:
1 2 3 4 5 6
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at redis.clients.util.Pool.getResource(Pool.java:53) at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66) ... ...
因为在之前创建创建集群时使用的IP是127.0.0.1,当返回(error) MOVED 10439 127.0.0.1:6381时,系统尝试连接本地的端口,然后连不上失败了
public static void main(String[] args) { List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); JedisShardInfo si = new JedisShardInfo("192.168.1.213", 6380); shards.add(si); si = new JedisShardInfo("192.168.1.213", 6381); shards.add(si); si = new JedisShardInfo("192.168.1.213", 6382); shards.add(si);
public static void main(String[] args) { List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); JedisShardInfo si = new JedisShardInfo("192.168.1.213", 6380); shards.add(si); si = new JedisShardInfo("192.168.1.213", 6381); shards.add(si); si = new JedisShardInfo("192.168.1.213", 6382); shards.add(si);
// 池连接 JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); ShardedJedisPool pool = new ShardedJedisPool(jedisPoolConfig, shards);