Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Jedis - I am a little confused as to how I should use the configuration end point in my code

$
0
0

So on the project I am currently working on we are making use of a redis cache on AWS, we had a AWS cluster mode disabled redis. Because of capacity we are going to transition to cluster mode enabled just so we can scale out horizontally if ever required. From what I have read one of the main benefits is the configuration end point which you can point requests to this and this will in turn delegate requests to the primary and read replica nodes for you and across shards.

Now with our current set up we had Jedis configured to point to the primary end point which just was a single node and therefore only had a single end point for reads and writes. I have changed the host to point to the configuration end point (assuming you could simply point to the configuration end point) of the shiny new cluster mode enabled redis and it throws 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;    }

So I guess the first question is, was my assumption wrong and I cannot change to simply use the configuration end point? If I can simply point to the cluster mode enabled endpoint is there something wrong with my code or is there anything extra I need to add to get it working?

If this is not possible there anything I would need to change in my code to make use of cluster mode enabled redis? Any help would be greatly appreciated. I am completely new to Redis and fairly new to AWS, code changes can be a little daunting sometimes for me.


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>