diff --git a/pom.xml b/pom.xml index 2486f880c8..7ff262aaaa 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-redis - 1.8.0.BUILD-SNAPSHOT + 1.8.0.DATAREDIS-551-SNAPSHOT Spring Data Redis diff --git a/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java b/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java index 60f4e7b795..a4e9c6c868 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java +++ b/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java @@ -40,6 +40,7 @@ * Redis specific {@link QueryEngine} implementation. * * @author Christoph Strobl + * @author Mark Paluch * @since 1.7 */ class RedisQueryEngine extends QueryEngine> { @@ -156,6 +157,10 @@ public Collection execute(final RedisOperationChain criteria, Comparator s @Override public long count(final RedisOperationChain criteria, final Serializable keyspace) { + if(criteria == null) { + return this.getAdapter().count(keyspace); + } + return this.getAdapter().execute(new RedisCallback() { @Override diff --git a/src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java b/src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java index c8458e95fa..fe958180b7 100644 --- a/src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java +++ b/src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java @@ -222,6 +222,24 @@ public void shouldApplyPageableCorrectlyWhenUsingFindAll() { assertThat(repo.findAll(firstPage.nextPageable()).getContent(), hasSize(1)); } + /** + * @see DATAREDIS-551 + */ + @Test + public void shouldApplyPageableCorrectlyWhenUsingFindByWithoutCriteria() { + + Person eddard = new Person("eddard", "stark"); + Person robb = new Person("robb", "stark"); + Person jon = new Person("jon", "snow"); + + repo.save(Arrays.asList(eddard, robb, jon)); + + Page firstPage = repo.findBy(new PageRequest(0, 2)); + assertThat(firstPage.getContent(), hasSize(2)); + assertThat(firstPage.getTotalElements(), is(equalTo(3L))); + assertThat(repo.findBy(firstPage.nextPageable()).getContent(), hasSize(1)); + } + /** * @see DATAREDIS-547 */ @@ -317,6 +335,8 @@ public static interface PersonRepository extends PagingAndSortingRepository findTop2By(); List findTop2ByLastname(String lastname); + + Page findBy(Pageable page); } /**