Home > Mobile >  Migrating spring-boot-redis and Jedis to use Jedis 4.2
Migrating spring-boot-redis and Jedis to use Jedis 4.2

Time:10-02

I have an application running older version of Spring Boot and Jedis, and would wish to upgrade to more recent versions so 2.7.3. for org.springframework.boot.spring-boot-starter-data-redis and 4.2.3 for redis.clients.jedis. This is my code with older Jedis.

@Bean
JedisConnectionFactory jedisConnectionFactory() {
    return new JedisConnectionFactory(new RedisStandaloneConfiguration(this.endpoint, this.port));
}
@Bean
public RedisTemplate<String, String> redisTemplate() {
    final RedisTemplate<String, String> template = new RedisTemplate<>();
    template.setConnectionFactory(jedisConnectionFactory());
    template.setKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new GenericToStringSerializer<>(Serializable.class));
    template.setValueSerializer(new GenericToStringSerializer<>(Serializable.class));
    return template;
}

However with upgrading Spring Boot and 4.x Jedis, I'm getting the following error

class file for redis.clients.jedis.JedisShardInfo not found

Jedis 3 to Jedis 4 Breaking Changes -document gives that JedisShardInfo indeed was removed from the Jedis code, and there are classes to replace that one. However, JedisConnectionFactory from org.springframework.data.redis.connection.jedis still seems to use JedisShardInfo-class internally, so coupling spring-boot-redis 2.7.3. with Jedis 4.x seems to lead into this scenario, at least when initializing the class with JedisConnectionFactory.

So what I'm wondering here is how should I couple spring-boot-redis with the newest Jedis 4.x to get it running with the RedisTemplate.

CodePudding user response:

Jedis 4 support is targeted for spring 3.0. If you really want to use Jedis 4.x, use spring 3.0 snapshots or milestone releases. Otherwise, keep using Jedis 3.x.

  • Related