只返回前 10 条记录 - Redis OM

问题描述 投票:0回答:2

我在 spring boot 中使用 Redis OM,我在查询对象时遇到了问题,因为它只返回前 10 条记录。

存储库类:

public interface RedisBillerRepository extends RedisDocumentRepository<Biller, Long> {
  List<Biller> findByClientIds(String clientId);
}

有没有办法返回所有具有特定 clientId 的对象?不只是前 10 个。

spring-boot redis spring-data-redis redisearch redis-om-spring
2个回答
2
投票

我找到的唯一方法是使用界面页面。例如你的存储库看起来像这样:

public interface RedisBillerRepository extends RedisDocumentRepository<Biller, Long> {
    Page<Biller> findByClientIds(String clientId, Pageable pageable);
}

你的班级可能看起来像这样

public class BillerService {

@Autowired
RedisBillerRepository redisBillerRepository;


public List<Biller> getAllClientsById(String clientId){
    Pageable pageRequest = PageRequest.of(0, 500000);
    Page<Biller> foundBillers = redisBillerRepository.findByClientIds(clientId, pageRequest);
    List<Biller> billersAsList = foundBillers.getContent();
    return billersAsList;
}

}

你现在必须设置限制。


1
投票

我是图书馆的作者……@member2 是正确的。 RediSearch 目前有一个默认的底层

FT.SEARCH
(https://redis.io/commands/ft.search/) 方法返回找到的前 10 条记录。要覆盖它,目前唯一的方法是使用 Spring 中的分页结构。

我将在即将发布的版本中公开一个配置参数来全局设置 MAX。

现在官方有两种方式:

  1. 使用 Spring 的 Pageable 类,如 https://github.com/redis/redis-om-spring/blob/main/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document /fixtures/MyDocRepository.java#L57然后在此处查看如何使用它的示例https://github.com/redis/redis-om-spring/blob/main/redis-om-spring/src/test/java /com/redis/om/spring/annotations/document/RedisDocumentSearchTest.java#L143
  2. 为所有查询配置默认限制,如此处所示https://github.com/redis/redis-om-spring/blob/main/redis-om-spring/src/test/resources/application.yaml
redis:
  om:
    spring:
      repository:
        query:
          limit: 20
© www.soinside.com 2019 - 2024. All rights reserved.