I have created a cluster on AWS Elasticache for Redis. The cluster operates in cluster mode enabled. There is 1 shard with 2 nodes currently created.
I'm trying to connect to the cluster through bastion host, thus using such port forwarding:
LocalForward localhost:6379 my-app.redis.apps.region.company.com:6379
I can reach the elasticache service with Spring Boot standalone configuration, but when fetching data from the cache, I get MOVED exception.
I have tried to switch the configuration to cluster mode using only cluster endpoint, but am getting:
Caused by: io.lettuce.core.RedisException: Cannot obtain initial Redis Cluster topology
at io.lettuce.core.cluster.RedisClusterClient.lambda$getPartitions$0(RedisClusterClient.java:329)
at io.lettuce.core.cluster.RedisClusterClient.get(RedisClusterClient.java:941)
at io.lettuce.core.cluster.RedisClusterClient.getPartitions(RedisClusterClient.java:329)
at org.springframework.data.redis.connection.lettuce.ClusterConnectionProvider.getConnectionAsync(ClusterConnectionProvider.java:92)
at org.springframework.data.redis.connection.lettuce.ClusterConnectionProvider.getConnectionAsync(ClusterConnectionProvider.java:40)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionProvider.getConnection(LettuceConnectionProvider.java:53)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1595)
... 134 common frames omitted
Caused by: io.lettuce.core.cluster.topology.DefaultClusterTopologyRefresh$CannotRetrieveClusterPartitions: Cannot retrieve cluster partitions from [redis://clustercfg.redis-*******.****.****.cache.amazonaws.com]
Here's my configuration:
@Configuration
class RedisConfiguration {
@Bean
fun connectionFactory(): RedisConnectionFactory? {
return LettuceConnectionFactory(
RedisClusterConfiguration().clusterNode(
"clustercfg.redis-*******.****.****.cache.amazonaws.com",
6379
)
)
}
@Bean
fun redisTemplate(redisConnectionFactory: RedisConnectionFactory) =
RedisTemplate<String, String>().apply {
setConnectionFactory(redisConnectionFactory)
StringRedisSerializer().let {
keySerializer = it
valueSerializer = it
}
}
@Bean
fun remoteConfigCacheManager(
connectionFactory: RedisConnectionFactory
): RedisCacheManager? {
return RedisCacheManager.builder(connectionFactory)
.withCacheConfiguration(
“CACHE_NAME”,
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1))
)
.build()
}
}
And there's the config in application.yml
redis:
host: ${REDIS_HOST:clustercfg.redis-*******.****.****.cache.amazonaws.com}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:<SOME_SECRET_PASSWORD>}
ssl: ${REDIS_SSL:true}
I've really browsed through every possible SO thread and could not find a solution. Can this be related to my bastion host?