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

Question about transitioning from using Jedis and RedisTemplate to JedisCluster

$
0
0

Originally in our code we were using RedisTemplate in conjuction with JedisConnectionFactory and JedisPoolConfig (see below) as we were using a single node cluster mode disabled redis.

   @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;    }

We want to transition to a cluster so we can scale out horizontally in the future and have multiple nodes. Thanks to a suggestion on another post I have successfully connected using JedisCluster. However I now have another issue where when we used RedisTemplate we used a number of commands such as redisTemplate.hasKey(cacheKey) to check if the key exists and redisTemplate.opsForValue().set among many others relevant to Redistemplate and these methods don't appear to be availible for JedisCluster.

My question is, is there a way I can use RedisTemplate in conjuction with JedisCluster to avoid re-coding these methods and just utilise the methods RedisTemplate offers or are there alternative commands that can be used in place of the ones offered by RedisTemplate? I have been googling for a while and can't really find anything useful for my problem unfortunately.

I appreciate any insight and help anybody can provide. I have only been looking at redis for a few days really and am completely new to how it works, the jedis, redis libraries.


Viewing all articles
Browse latest Browse all 2203

Trending Articles