0

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 ?

asked Apr 2, 2025 at 23:53

1 Answer 1

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);
answered Apr 3, 2025 at 21:55
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.