【问题标题】:Spring boot data redis doesn't return value from repositorySpring引导数据redis不从存储库返回值
【发布时间】:2020-10-28 18:36:17
【问题描述】:

我想在我的 Spring Boot 应用程序中使用 Redis 存储库,但每次当我想重新运行 findById 或 findByName 等方法时,每次存储库返回 null 但当我运行 findAll 或保存一切正常时。这是我的代码: 我主要使用了这个注释:@EnableRedisRepository("com.redis.repository.redis") 我创建了 RedisConfig 文件:

@Configuration
public class RedisConfig {

@Bean
public LettuceConnectionFactory redisConnectionFactory() {
    return new LettuceConnectionFactory();
}

@Bean
public RedisTemplate<?, ?> redisTemplate() {
    RedisTemplate<?, ?> template = new RedisTemplate<>();
    template.setConnectionFactory(redisConnectionFactory());
    return template;
}

}

我还在我的域类上方添加了注释@RedisHash。

@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash
public class Product {

@Id
private Long id;

private String name;

private String description;

private Double price;

private Double quantity;

}

这是我的 pom 文件

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
        </dependency>

有谁知道我做错了什么?

编辑:

我添加到字段 @Indexed 并且它可以正常工作,但对于旧版本它仍然无法正常工作

【问题讨论】:

  • 你有云共享的 git repo 吗?
  • @KavithakaranKanapathippillai 我没有 git repo,但我更新了我的问题。我希望它会足够

标签: spring-boot redis spring-data


【解决方案1】:

如果你能发布你的redis版本、spring-data-redis版本和存储库代码会更有帮助。

另外,你可以使用redis的MONITOR命令来查看你的服务器到底向redis服务器发送了什么命令,这将有助于调试。

【讨论】:

  • 我通过在字段中添加@Indexed 解决了我的问题,但它不适用于旧值
猜你喜欢
  • 2013-10-17
  • 1970-01-01
  • 2019-06-25
  • 2021-06-24
  • 2019-04-09
  • 2016-07-20
  • 1970-01-01
  • 2018-09-08
  • 1970-01-01
相关资源
最近更新 更多