How to connect to AWS ELasticCache Redis Cluster using Spring-data-redis. I am using redis as a datastore and would like to achieve
Assuming :
package com.example.config;
import java.time.Duration;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
@Configuration
public class RedisConfiguration {
@Bean
public JedisClientConfiguration getJedisClientConfiguration(@Value("$REDIS_CONNECTION_TIMEOUT}") final Duration timeout) {
JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfigurationBuilder = JedisClientConfiguration.builder();
jedisClientConfigurationBuilder.connectTimeout(timeout);
jedisClientConfigurationBuilder.usePooling();
return jedisClientConfigurationBuilder.build();
}
@Bean
public RedisClusterConfiguration getRedisClusterConfiguration(@Value("${REDIS_HOST}") final String host,
@Value("${REDIS_PORT}") final Integer port) {
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration();
redisClusterConfiguration = redisClusterConfiguration.clusterNode(host, port);
return redisClusterConfiguration;
}
@Bean
public JedisConnectionFactory jedisConnectionFactory(
@Qualifier("getRedisClusterConfiguration") final RedisClusterConfiguration redisClusterConfiguration,
@Qualifier("getJedisClientConfiguration") final JedisClientConfiguration jedisClientConfiguration) {
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(redisClusterConfiguration, jedisClientConfiguration);
return connectionFactory;
}
}
Missing