[英]Why spring data redis findById returns null values in Optional after upgrading to version 2.3.2.RELEASE
spring repository findById() is working fine on spring-data-redis version 2.3.1.RELEASE spring 存储库 findById() 在 spring-data-redis 版本 2.3.1.RELEASE 上运行良好
its failed on spring-data-redis version 2.3.2.RELEASE它在 spring-data-redis 版本 2.3.2.RELEASE 上失败
Here is link to sample repository, edit version in pom.xml file, then run, then see the issue这是示例存储库的链接,在 pom.xml 文件中编辑版本,然后运行,然后查看问题
https://github.com/mnguyencntt/spring-data-redis-optional https://github.com/mnguyencntt/spring-data-redis-optional
My logic code is very simple:我的逻辑代码很简单:
if studentId found, return existing RedisStudent object.如果找到 studentId,则返回现有的 RedisStudent object。
else create new RedisStudent & store in Redis, return new RedisStudent object.否则创建新的 RedisStudent 并存储在 Redis 中,返回新的 RedisStudent object。
RedisInfoController.java RedisInfoController.java
final Optional<RedisStudent> redisExisting = redisStudentRepository.findById(studentId);
if (redisExisting.isPresent()) {
// Spring boot 2.3.2 will print out: RedisStudent(id=null, name=null, age=null, creationTime=null)
// Spring boot 2.3.1 will print out: RedisStudent(id=12345, name=Minh, age=28, creationTime=2020-07-28T21:31:18.318)
log.info("{}", redisExisting.get());
return redisExisting.get();
}
// Spring boot 2.3.1 will print out: Optional.empty
log.info("{}", redisExisting);
RedisStudent student = new RedisStudent();
student.setId(studentId);
student.setName("Minh");
student.setAge("28");
student.setCreationTime(LocalDateTime.now());
return redisStudentRepository.save(student);
You are running into DATAREDIS-1191 .您正在运行DATAREDIS-1191 。 It will be fixed in the 2.3.3.RELEASE .它将在 2.3.3.RELEASE 中修复。
Maybe it has something to do the fact that studentId is null in your controller?也许它与你的 controller 中的 studentId 是 null 的事实有关?
You are not taking studentId in the request param.您没有在请求参数中使用 studentId。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.