-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: handle RediSearch Dialect 3 in repositories (add @UseDialect…
… annotation for repo methods) - (resolves gh-476)
- Loading branch information
Showing
10 changed files
with
271 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
redis-om-spring/src/main/java/com/redis/om/spring/annotations/Dialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.redis.om.spring.annotations; | ||
|
||
public enum Dialect { | ||
ONE(1), | ||
TWO(2), | ||
THREE(3); | ||
|
||
private final int value; | ||
Dialect(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
redis-om-spring/src/main/java/com/redis/om/spring/annotations/UseDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.redis.om.spring.annotations; | ||
|
||
|
||
|
||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) | ||
public @interface UseDialect { | ||
Dialect dialect() default Dialect.ONE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/DialectThreeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.redis.om.spring.annotations.document; | ||
|
||
import com.redis.om.spring.AbstractBaseDocumentTest; | ||
import com.redis.om.spring.fixtures.document.model.TestResultRedisModel; | ||
import com.redis.om.spring.fixtures.document.repository.TestResultRedisRepository; | ||
import com.redis.om.spring.search.stream.EntityStream; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; | ||
import redis.clients.jedis.JedisPooled; | ||
import redis.clients.jedis.UnifiedJedis; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DialectThreeTest extends AbstractBaseDocumentTest { | ||
|
||
@Autowired | ||
TestResultRedisRepository testResultRedisRepository; | ||
|
||
@Autowired | ||
JedisConnectionFactory jedisConnectionFactory; | ||
|
||
@Autowired | ||
EntityStream es; | ||
|
||
private UnifiedJedis jedis; | ||
|
||
@BeforeEach | ||
void cleanUp() { | ||
flushSearchIndexFor(TestResultRedisModel.class); | ||
|
||
if (testResultRedisRepository.count() == 0) { | ||
testResultRedisRepository.save(TestResultRedisModel.of(123L, "123-123-123-123-123", "9_TNR290INP\\-WEE2024011124\\.xml", "REJECTED")); | ||
testResultRedisRepository.save(TestResultRedisModel.of(456L, "456-456-456-456-456", "8_TNR290INP\\-WEE2024011124\\.xml", "ACCEPTED")); | ||
} | ||
|
||
jedis = new JedisPooled(Objects.requireNonNull(jedisConnectionFactory.getPoolConfig()), | ||
jedisConnectionFactory.getHostName(), jedisConnectionFactory.getPort()); | ||
} | ||
|
||
@Test | ||
void testDialect3() { | ||
var results = testResultRedisRepository.findAllByFilenameIs("9_TNR290INP\\-WEE2024011124\\.xml"); | ||
assertThat(results).hasSize(1); | ||
var result = results.iterator().next(); | ||
assertThat(result.getUuid()).isEqualTo("123-123-123-123-123"); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
redis-om-spring/src/test/java/com/redis/om/spring/annotations/hash/DialectThreeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.redis.om.spring.annotations.hash; | ||
|
||
import com.redis.om.spring.AbstractBaseDocumentTest; | ||
import com.redis.om.spring.AbstractBaseEnhancedRedisTest; | ||
import com.redis.om.spring.fixtures.hash.model.TestResultRedisModel; | ||
import com.redis.om.spring.fixtures.hash.repository.TestResultRedisRepository; | ||
import com.redis.om.spring.search.stream.EntityStream; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; | ||
import redis.clients.jedis.JedisPooled; | ||
import redis.clients.jedis.UnifiedJedis; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DialectThreeTest extends AbstractBaseEnhancedRedisTest { | ||
|
||
@Autowired | ||
TestResultRedisRepository testResultRedisRepository; | ||
|
||
@Autowired | ||
JedisConnectionFactory jedisConnectionFactory; | ||
|
||
@Autowired | ||
EntityStream es; | ||
|
||
private UnifiedJedis jedis; | ||
|
||
@BeforeEach | ||
void cleanUp() { | ||
flushSearchIndexFor(TestResultRedisModel.class); | ||
|
||
if (testResultRedisRepository.count() == 0) { | ||
testResultRedisRepository.save(TestResultRedisModel.of(123L, "123-123-123-123-123", "9_TNR290INP\\-WEE2024011124\\.xml", "REJECTED")); | ||
testResultRedisRepository.save(TestResultRedisModel.of(456L, "456-456-456-456-456", "8_TNR290INP\\-WEE2024011124\\.xml", "ACCEPTED")); | ||
} | ||
|
||
jedis = new JedisPooled(Objects.requireNonNull(jedisConnectionFactory.getPoolConfig()), | ||
jedisConnectionFactory.getHostName(), jedisConnectionFactory.getPort()); | ||
} | ||
|
||
@Test | ||
void testDialect3() { | ||
var results = testResultRedisRepository.findAllByFilenameIs("9_TNR290INP\\-WEE2024011124\\.xml"); | ||
assertThat(results).hasSize(1); | ||
var result = results.iterator().next(); | ||
assertThat(result.getUuid()).isEqualTo("123-123-123-123-123"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...pring/src/test/java/com/redis/om/spring/fixtures/document/model/TestResultRedisModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.redis.om.spring.fixtures.document.model; | ||
|
||
import com.redis.om.spring.annotations.Document; | ||
import com.redis.om.spring.annotations.Indexed; | ||
import com.redis.om.spring.annotations.Searchable; | ||
import lombok.*; | ||
import org.springframework.data.annotation.Id; | ||
|
||
@Data | ||
@RequiredArgsConstructor(staticName = "of") | ||
@NoArgsConstructor(force = true) | ||
@Document("TestResultRedis") | ||
public class TestResultRedisModel { | ||
@Id | ||
@Indexed | ||
@NonNull | ||
private Long id; | ||
|
||
@Indexed | ||
@NonNull | ||
String uuid; | ||
|
||
@Searchable | ||
@NonNull | ||
String filename; | ||
|
||
@Indexed | ||
@NonNull | ||
String status; | ||
} |
13 changes: 13 additions & 0 deletions
13
...test/java/com/redis/om/spring/fixtures/document/repository/TestResultRedisRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.redis.om.spring.fixtures.document.repository; | ||
|
||
import com.redis.om.spring.annotations.UseDialect; | ||
import com.redis.om.spring.annotations.Dialect; | ||
import com.redis.om.spring.fixtures.document.model.TestResultRedisModel; | ||
import com.redis.om.spring.repository.RedisDocumentRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface TestResultRedisRepository extends RedisDocumentRepository<TestResultRedisModel, Long> { | ||
@UseDialect(dialect = Dialect.THREE) | ||
List<TestResultRedisModel> findAllByFilenameIs(String filename); | ||
} |
34 changes: 34 additions & 0 deletions
34
...om-spring/src/test/java/com/redis/om/spring/fixtures/hash/model/TestResultRedisModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.redis.om.spring.fixtures.hash.model; | ||
|
||
import com.redis.om.spring.annotations.Document; | ||
import com.redis.om.spring.annotations.Indexed; | ||
import com.redis.om.spring.annotations.Searchable; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
@Data | ||
@RequiredArgsConstructor(staticName = "of") | ||
@NoArgsConstructor(force = true) | ||
@RedisHash("TestResultRedis") | ||
public class TestResultRedisModel { | ||
@Id | ||
@Indexed | ||
@NonNull | ||
private Long id; | ||
|
||
@Indexed | ||
@NonNull | ||
String uuid; | ||
|
||
@Searchable | ||
@NonNull | ||
String filename; | ||
|
||
@Indexed | ||
@NonNull | ||
String status; | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/test/java/com/redis/om/spring/fixtures/hash/repository/TestResultRedisRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.redis.om.spring.fixtures.hash.repository; | ||
|
||
import com.redis.om.spring.annotations.Dialect; | ||
import com.redis.om.spring.annotations.UseDialect; | ||
|
||
import com.redis.om.spring.fixtures.hash.model.TestResultRedisModel; | ||
import com.redis.om.spring.repository.RedisDocumentRepository; | ||
import com.redis.om.spring.repository.RedisEnhancedRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface TestResultRedisRepository extends RedisEnhancedRepository<TestResultRedisModel, Long> { | ||
@UseDialect(dialect = Dialect.THREE) | ||
List<TestResultRedisModel> findAllByFilenameIs(String filename); | ||
} |