I'm using SSL enabled Redis (ElasticCache from AWS), and having difficulty in connecting to it using Spring Data Redis.
(Note that the connectivity works fine, if I use plain Jedis or Jedis Pool with Spring).
Following is the code snippet:
@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<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
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<Object>(Object.class));
return template;
}
}
RedisTemplate usage:
@Autowired
private RedisTemplate<String, String> redistemplate;
public void api2() {
HashOperations<String, Object, Object> hashOperations = redistemplate.opsForHash();
hashOperations.put("KEY", "1", "one");
}
}
Any operation using RedisTemplate throws below exception:
"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]"
Note:
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.
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.
Any help or pointers are appreciated.
redisHost + ":"+ redisPort
? – Phio