I have a spring app deployed to AWS Kubernetes, and an AWS elasticache with transit encryption mode set to required. When the java code below gets executed, it throws an exception
Java code:
JedisCluster jedisCluster = new JedisCluster(new HostAndPort(host, port));//host is the redis cluster endpoint
Error:
<JedisClusterOperationException> Could not initialize cluster slots cache
Maven dependency:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.2.0</version>
</dependency>
However, when the encryption mode is set to Preferred, the java code above connects to the elasticache fine and it gets executed without throwing an exception.
Any idea how to fix this issue with keeping the encryption mode set to required ?
1 Answer 1
After looking into JedisCluster class in depth, I was able to find a solution for the issue above.
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLParameters sslParameters = new SSLParameters();
JedisClientConfig clientConfig = DefaultJedisClientConfig.builder()
.ssl(true)
.sslSocketFactory(sslSocketFactory)
.sslParameters(sslParameters)
.build();
Set<HostAndPort> clusterNodes = Set.of(new HostAndPort(host, port));
JedisCluster jedisCluster = new JedisCluster(clusterNodes, clientConfig);
Comments
Explore related questions
See similar questions with these tags.