skip to Main Content

I’m using Redis OM for spring boot, I am having trouble querying objects because it only returns the first 10 records.

Repository Class:

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

Is there a way to return ALL the objects with the specific clientId? Not the first 10 only.

2

Answers


  1. The only way which i found was with the interface Page. For example your Repository would look like this:

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

    And your class could look like this

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

    }

    You have to set the limit for now.

    Login or Signup to reply.
  2. I’m the author of the library… @member2 is correct. RediSearch currently has a default for the underlying FT.SEARCH (https://redis.io/commands/ft.search/) method of returning the first 10 records found. To override that, the only way to do so currently is to use the Pagination constructs in Spring.

    I will expose a configuration parameter in upcoming versions to set the MAX globally.

    Now there are officially two ways:

    1. Use Spring’s Pageable class like 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 then see example of how to use it here 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. Configure a default LIMIT for all your queries as shown here https://github.com/redis/redis-om-spring/blob/main/redis-om-spring/src/test/resources/application.yaml
    redis:
      om:
        spring:
          repository:
            query:
              limit: 20
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search