spring repository findById() is working fine on spring-data-redis version 2.3.1.RELEASE
its failed on spring-data-redis version 2.3.2.RELEASE
Here is link to sample repository, edit version in pom.xml file, then run, then see the issue
https://github.com/mnguyencntt/spring-data-redis-optional
My logic code is very simple:
if studentId found, return existing RedisStudent object.
else create new RedisStudent & store in Redis, return new RedisStudent object.
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 . It will be fixed in the 2.3.3.RELEASE .
Maybe it has something to do the fact that studentId is null in your controller?
You are not taking studentId in the request param.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.