Spring Boot Upgrade Redis - Null key returned for cache operation

116 views Asked by At

After the spring 3.x upgrade Redis Cache gives

Null key returned for cache operation

spring-boot version: 3.2.2

<dependency>
  <groupId>redis.clients</groupId>
  <artifactId>jedis</artifactId>
  <version>5.1.0</version>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-redis</artifactId>
  <exclusions>
    <exclusion>
      <groupId>io.lettuce</groupId>
        <artifactId>lettuce-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Cachable Method:

@Cacheable(value = "user", key = "#username", unless = "#result == null")
public String findUsername(String username) {
    ...
}

but if I use key = "#a0" instead of key = "#username", the problem is solved.

@Cacheable(value = "user", key = "#a0", unless = "#result == null")
public String findUsername(String username) {
    ...
}

There was no need to do it this way in the previous version. My previous versions:

spring-boot version: 2.7.4
redis.clients jedis version :3.9.0

What is the reason?

2

There are 2 answers

0
Iqbal AISSAOUI On BEST ANSWER

Spel is impacted in the 3.1 to 3.2 upgrade, you need to pass extra flag to maven compiler to preserve parameter name discovery

Please check

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#parameter-name-discovery

https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
    <parameters>true</parameters>
</configuration>
0
kernel On