Previously, we were using Redis with cluster mode disabled via AWS ElastiCache.
Our Java code using Jedis was pointing to the primary single node endpoint, which was used for reads and writes.
We've now enabled cluster mode.
We have now changed the code to point to the configuration endpoint of the new Redis cluster however it is now throwing errors whenever receiving requests, see below:
Redis Unavailable. Continue using the Queue requestMessage instead.org.springframework.data.redis.ClusterRedirectException: Redirect: slot 2356 to [ipaddress]:6379.; nested exception is redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 2356 [ipaddress]:6379
Our configuration code is as below:
@Bean(name = "redisTemplate") public RedisTemplate<String, String> getRedisTemplate(JedisConnectionFactory jedisConnectionFactory) { RedisTemplate template = new RedisTemplate(); template.setConnectionFactory(jedisConnectionFactory); template.setKeySerializer(new StringRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer()); template.setHashValueSerializer(new StringRedisSerializer()); template.afterPropertiesSet(); return template; } @Bean JedisConnectionFactory jedisConnectionFactory(Configuration config) { JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(); jedisConnectionFactory.setHostName(config.get(HOST)); jedisConnectionFactory.setPort(config.getInt(PORT)); jedisConnectionFactory.setUsePool(true); jedisConnectionFactory.setPoolConfig(createJedisPoolConfig(config)); jedisConnectionFactory.afterPropertiesSet(); return jedisConnectionFactory; } JedisPoolConfig createJedisPoolConfig(Config config) { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(config.getInt(MAX, 8)); poolConfig.setMaxIdle(config.getInt(MAXIDLE, 8)); poolConfig.setMinIdle(config.getInt(MINIDLE, 1)); poolConfig.setTestOnBorrow(true); poolConfig.setTestOnReturn(true); return poolConfig; }
Shouldn't just changing Jedis to point to the configuration endpoint be enough?
Do I need to change anything in my code?