title: "Cannot get Jedis connection" when using SSL with Redis and Spring Data Redis
body: <p>I'm using SSL enabled Redis (ElasticCache from AWS), and having difficulty in connecting to it using Spring Data Redis.</p>
  
  <p>(Note that the connectivity works fine, if I use plain Jedis or Jedis Pool with Spring).</p>
  
  <p>Following is the code snippet:</p>
  
  <pre><code>    @Value("${vcap.services.myredis.credentials.host}")
      private String redisHost;
  
      @Value("${vcap.services.myredis.credentials.password}")
      private String redisPassword;
  
      @Value("${vcap.services.myredis.credentials.port}")
      private String redisPort;
  
      public RedisTemplate&lt;String, Object&gt; redisTemplate() {
  
          final RedisTemplate&lt;String, Object&gt; template = new RedisTemplate&lt;String, Object&gt;();
  
  
          String hostUri = "rediss://:" + redisPassword + "@" + redisHost + redisPort;    
  
          JedisShardInfo info = new JedisShardInfo(hostUri);
  
          JedisConnectionFactory conn =  new JedisConnectionFactory(info);
  
          conn.afterPropertiesSet();
  
          template.setConnectionFactory(conn);
          template.setValueSerializer(new GenericToStringSerializer&lt;Object&gt;(Object.class));
          return template;
      }
  
  }
  </code></pre>
  
  <p>RedisTemplate usage:    </p>
  
  <pre><code>    @Autowired
      private RedisTemplate&lt;String, String&gt; redistemplate;
  
  
      public void api2() {
  
          HashOperations&lt;String, Object, Object&gt; hashOperations = redistemplate.opsForHash();
  
          hashOperations.put("KEY", "1", "one"); 
      }
  
  }
  </code></pre>
  
  <p>Any operation using RedisTemplate throws below exception:</p>
  
  <blockquote>
    <p>"nested exception is
    org.springframework.data.redis.RedisConnectionFailureException: Cannot
    get Jedis connection; nested exception is
    redis.clients.jedis.exceptions.JedisConnectionException: Could not get
    a resource from the pool] with root cause
    2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0] [OUT]
    java.net.SocketException: Connection reset
    2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0] [OUT] at
    java.net.SocketInputStream.read(SocketInputStream.java:210)
    ~[na:1.8.0_141] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0] [OUT]
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    ~[na:1.8.0_141] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0] [OUT]
    at java.net.SocketInputStream.read(SocketInputStream.java:127)
    ~[na:1.8.0_141] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0] [OUT]
    at
    redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196)
    ~[jedis-2.9.0.jar!/:na] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0]
    [OUT] at
    redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
    ~[jedis-2.9.0.jar!/:na] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0]
    [OUT] at redis.clients.jedis.Protocol.process(Protocol.java:151)
    ~[jedis-2.9.0.jar!/:na] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0]
    [OUT] at redis.clients.jedis.Protocol.read(Protocol.java:215)
    ~[jedis-2.9.0.jar!/:na] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0]
    [OUT] at
    redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
    ~[jedis-2.9.0.jar!/:na] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0]
    [OUT] at
    redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
    ~[jedis-2.9.0.jar!/:na] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0]
    [OUT] at redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:2139)
    ~[jedis-2.9.0.jar!/:na] 2018-01-22T15:59:35.531+11:00 [APP/PROC/WEB/0]
    [OUT] at
    redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:108)
    ~[jedis-2.9.0.jar!/:na]"</p>
  </blockquote>
  
  <p>Note:</p>
  
  <ol>
  <li><p>This is not an issue with SSL Certs as SSL certs for AWS are already present in the JVM Trust store and note that JedisPool is working with SSL.</p></li>
  <li><p>I suspect that somehow the JedisConnectionFactory is ignoring and not making a SSL connection. I tried other arg constructors of JedisConnectionFactory like setting the useSSL to true, etc, without luck.</p></li>
  </ol>
  
  <p>Any help or pointers are appreciated.</p>