skip to Main Content

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);

2

Answers


  1. Maybe it has something to do the fact that studentId is null in your controller?

    You are not taking studentId in the request param.

    Login or Signup to reply.
  2. You are running into DATAREDIS-1191. It will be fixed in the 2.3.3.RELEASE.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search