spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

Repository Pattern - findAll pagination returns inconsistent result with redis read replicas

Open sureshkmit opened this issue 5 months ago • 0 comments

Sample Usage:

    Example entity = Example.of(entityAttributes);
    final Pageable pageable = Pageable.ofSize(pageSize).withPage(pageNumber);
    return repository.findAll(entity, pageable);

Redis set data type doesn't guarantee the element order when retrieved from replica. As the keys returned by the findKeys method in RedisQueryEngine are not ordered, it causes issues when applying subList for pagination, especially with Redis read replicas. To ensure consistent pagination, the list of keys should be sorted before sublisting.

RedisQueryEngine.java#L118

sureshkmit avatar Jun 24 '25 12:06 sureshkmit