相关文章推荐
不敢表白的牛肉面  ·  python(Redis 中 ...·  7 月前    · 
讲道义的小熊猫  ·  postgres array ...·  1 年前    · 
没有腹肌的煎饼果子  ·  如何在pandas ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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",
    @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?

first, check whether you can access Redis server with a local redis client by using redis-cli -c and see if it redirects – namila007 Sep 6, 2022 at 11:39 Using that command I get "logged" to 127.0.0.1:6379. Can use all the commands like KEYS '*', FLUSHALL etc. – Maciaz Sep 6, 2022 at 11:42 yeh i mean try adding keys like 'a','t','x' and then try to retrieve them. if you are getting moved again even with the -c option ,check the configurations of elasticache – namila007 Sep 7, 2022 at 7:48

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.