Originally in our code we were using RedisTemplate
in conjuction with JedisConnectionFactory
and JedisPoolConfig
as we were using a Redis on a single node:
@Bean(name = "redisTemplate")
public RedisTemplate<String, String> getRedisTemplate(JedisConnectionFactory jedisConnectionFactory) {
RedisTemplate template = new RedisTemplate();
template.setConnectionFactory(jedisConnectionFactory);
// ...
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();
// ...
return poolConfig;
}
We are now using JedisCluster
as we are using a Redis cluster.
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
.
These methods don't appear to be available for JedisCluster
.
Is there a way I can use RedisTemplate in conjunction 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?