【问题标题】:Why spring data redis findById returns null values in Optional after upgrading to version 2.3.2.RELEASE为什么spring data redis findById在升级到2.3.2.RELEASE版本后在Optional中返回null值
【发布时间】:2020-07-28 10:31:15
【问题描述】:

spring 存储库 findById() 在 spring-data-redis 版本 2.3.1.RELEASE 上运行良好

它在 spring-data-redis 版本 2.3.2.RELEASE 上失败


这里是示例存储库的链接,在 pom.xml 文件中编辑版本,然后运行,然后查看问题

https://github.com/mnguyencntt/spring-data-redis-optional


我的逻辑代码很简单:

如果找到 studentId,则返回现有的 RedisStudent 对象。

否则在 Redis 中创建新的 RedisStudent 并存储,返回新的 RedisStudent 对象。


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

【问题讨论】:

标签: java spring-boot spring-data-jpa spring-data-redis


【解决方案1】:

您遇到了DATAREDIS-1191。它将是fixed in the 2.3.3.RELEASE

【讨论】:

【解决方案2】:

也许这与你的控制器中的 studentId 为空有关?

您没有在请求参数中使用 studentId。

【讨论】:

  • studentId 的值始终为“12345”
猜你喜欢
  • 2020-06-23
  • 2017-06-24
  • 2016-04-19
  • 1970-01-01
  • 2020-04-22
  • 2023-03-12
  • 1970-01-01
  • 2019-03-14
  • 2019-12-25
相关资源
最近更新 更多