title: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool while connecting to redis cluster
body: <p>I am trying to connect to redis cluster using java <strong>JedisCluster</strong> client .</p>
  
  <p>First I made Redis Cluster using this docker image </p>
  
  <p><a href="https://hub.docker.com/r/grokzen/redis-cluster/" rel="nofollow noreferrer">
  grokzen/redis-cluster</a></p>
  
  <p>Created 6 nodes (3 masters &amp;&amp; 3 slaves) </p>
  
  <p>Using docker machine in windows I started redis cluster using this command </p>
  
  <pre><code>docker run -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 -p 7006:7006 -p 7007:7007 dockerImageId
  </code></pre>
  
  <p><strong>Redis Cluster starting short Log :</strong></p>
  
  <blockquote>
    <blockquote>
      <p>Using 3 masters:</p>
      
      <p>172.17.0.2:7000</p>
      
      <p>172.17.0.2:7001</p>
      
      <p>172.17.0.2:7002 </p>
    </blockquote>
    
    <p>Adding replica 172.17.0.2:7004 to 172.17.0.2:7000 Adding replica
    172.17.0.2:7005</p>
    
    <p>to 172.17.0.2:7001 Adding replica</p>
    
    <blockquote>
      <p>172.17.0.2:7003 to 172.17.0.2:7002</p>
    </blockquote>
  </blockquote>
  
  <p><strong>Java Client for Redis Cluster:</strong></p>
  
  <pre><code>Set&lt;HostAndPort&gt; jedisClusterNodes = new HashSet&lt;HostAndPort&gt;();
          jedisClusterNodes.add(new HostAndPort("192.168.99.100", 7000));
          JedisCluster jc = new JedisCluster(jedisClusterNodes);
          jc.set("key", "Redis-Val");
          String value = jc.get("key");
          System.out.println("key is : "+value);
  </code></pre>
  
  <p>After running this code I got this Exception  </p>
  
  <blockquote>
    <p>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)
      at
    redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:116)
      at
    redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
      at
    redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
      at
    redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
      at
    redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
      at
    redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:31)
      at redis.clients.jedis.JedisCluster.set(JedisCluster.java:103)  at
    redis.redis_example.App.main(App.java:20) Caused by:
    redis.clients.jedis.exceptions.JedisConnectionException:
    java.net.SocketTimeoutException: connect timed out</p>
  </blockquote>
  
  <p>I have checked that redis is running on any node in the cluster by telnet command :</p>
  
  <blockquote>
    <p>telnet 192.168.99.100 7000 </p>
  </blockquote>
  
  <p>connected successfully</p>