DATAREDIS-623 - Fix RedisQueryEngine.count(…) with proper SINTER/SUNION usage.
Backport of RedisQueryEngine#count(RedisOperationChain, Serializable) fix using multiple indexed keys. Related ticket: DATAREDIS-605. Original pull request: #330.
This commit is contained in:
committed by
Mark Paluch
parent
c6540ec387
commit
f61b0d6fad
28
pom.xml
28
pom.xml
@@ -31,26 +31,26 @@
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
<version>${pool}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spring -->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-keyvalue</artifactId>
|
||||
@@ -78,35 +78,35 @@
|
||||
</dependency>
|
||||
|
||||
<!-- REDIS Drivers -->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>${jedis}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jredis</groupId>
|
||||
<artifactId>jredis-core-api</artifactId>
|
||||
<version>${jredis}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jredis</groupId>
|
||||
<artifactId>jredis-core-ri</artifactId>
|
||||
<version>${jredis}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.spullara.redis</groupId>
|
||||
<artifactId>client</artifactId>
|
||||
<version>${srp}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>biz.paluch.redis</groupId>
|
||||
<artifactId>lettuce</artifactId>
|
||||
@@ -219,7 +219,7 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
@@ -240,12 +240,12 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>wagon-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
@@ -259,13 +259,13 @@
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.jfrog.buildinfo</groupId>
|
||||
<artifactId>artifactory-maven-plugin</artifactId>
|
||||
<inherited>false</inherited>
|
||||
</plugin>
|
||||
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
@@ -175,14 +175,17 @@ class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationC
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
|
||||
String key = keyspace + ":";
|
||||
byte[][] keys = new byte[criteria.getSismember().size()][];
|
||||
int i = 0;
|
||||
for (Object o : criteria.getSismember()) {
|
||||
keys[i] = getAdapter().getConverter().getConversionService().convert(key + o, byte[].class);
|
||||
long result = 0;
|
||||
|
||||
if (!criteria.getOrSismember().isEmpty()) {
|
||||
result += connection.sUnion(keys(keyspace + ":", criteria.getOrSismember())).size();
|
||||
}
|
||||
|
||||
return (long) connection.sInter(keys).size();
|
||||
if (!criteria.getSismember().isEmpty()) {
|
||||
result += connection.sInter(keys(keyspace + ":", criteria.getSismember())).size();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -345,6 +345,22 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
assertThat(result, not(hasItems(p1)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-623
|
||||
public void pageableQueryWithTwoKeywordsShouldReturnCorrectly() {
|
||||
|
||||
Person eddard = new Person("eddard", "stark");
|
||||
Person robb = new Person("robb", "stark");
|
||||
Person sansa = new Person("sansa", "stark");
|
||||
|
||||
repo.save(Arrays.asList(eddard, robb, sansa));
|
||||
|
||||
Page<Person> page1 = repo.findByFirstnameAndLastname("sansa", "stark", new PageRequest(0, 2));
|
||||
|
||||
assertThat(page1.getNumberOfElements(), is(1));
|
||||
assertThat(page1.getContent(), hasSize(1));
|
||||
assertThat(page1.getTotalElements(), is(1L));
|
||||
}
|
||||
|
||||
public static interface PersonRepository extends PagingAndSortingRepository<Person, String> {
|
||||
|
||||
List<Person> findByFirstname(String firstname);
|
||||
@@ -355,6 +371,8 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
|
||||
List<Person> findByFirstnameAndLastname(String firstname, String lastname);
|
||||
|
||||
Page<Person> findByFirstnameAndLastname(String firstname, String lastname, Pageable page);
|
||||
|
||||
List<Person> findByFirstnameOrLastname(String firstname, String lastname);
|
||||
|
||||
List<Person> findFirstBy();
|
||||
|
||||
Reference in New Issue
Block a user