title: SpringBoot Elasticache JedisMovedDataException: MOVED
body: <p>Trying to use SpringBoot with SpringData with Elasticache:</p>
  
  <p>application.properties: </p>
  
  <pre><code>spring.redis.host=XXXX-dev.XXXX.clusXXXcfg.XXX.cache.amazonaws.com
  spring.redis.port=6379
  </code></pre>
  
  <p>CacheConfiguration:</p>
  
  <pre><code>@Configuration
  @PropertySource("classpath:application.properties")
  public class CacheConfiguration {
  
  
  @Value("${spring.redis.host}")
  private String redisHostName;
  
  @Bean
  public RedisTemplate&lt;String, Company&gt; redisTemplate() {
      RedisTemplate&lt;String, Company&gt; template = new RedisTemplate();
      template.setConnectionFactory(jedisConnectionFactory());
      return template;
  }
  
  @Bean
  JedisConnectionFactory jedisConnectionFactory() {
      JedisConnectionFactory factory = new JedisConnectionFactory();
      factory.setHostName(redisHostName);
      factory.setUsePool(true);
      return factory;
  }
  
  
  @Bean
  public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
      return new PropertySourcesPlaceholderConfigurer();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Service call:</p>
  
  <pre><code>@Autowired
  RedisTemplate&lt;String, Company&gt; redisTemplate;
  
  private ValueOperations valueOperations;
  
  @PostConstruct
  private void init() {
      valueOperations = redisTemplate.opsForValue();
  }
  
  @Override
  public String createOtp(Company company) {
      String token = UUID.randomUUID().toString();
      valueOperations.set(token, company);
      valueOperations.getOperations().expire(token, 5, TimeUnit.MINUTES);
      return token;
  }
  </code></pre>
  
  <p>Error:</p>
  
  <p>org.springframework.data.redis.ClusterRedirectException: Redirect: slot 7228 to 10.<strong>.</strong>.<strong>:6379.*</strong></p>
  
  <p>redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 7228 10.<strong>.</strong>.<strong>:6379.*</strong></p>
  
  <p>The question is - what is wrong with configuration?</p>