-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: add ability for repositories to retrieve TTL for an object * feature: enable @timetolive annotation and @document timeToLive property for JSON-mapped entities * test: add TTL tests for @RedisHash
- Loading branch information
Showing
20 changed files
with
397 additions
and
22 deletions.
There are no files selected for viewing
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
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
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
65 changes: 65 additions & 0 deletions
65
redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/DocumentTTLTests.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,65 @@ | ||
package com.redis.om.spring.annotations.document; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
|
||
import com.redis.om.spring.AbstractBaseDocumentTest; | ||
import com.redis.om.spring.annotations.document.fixtures.ExpiringPerson; | ||
import com.redis.om.spring.annotations.document.fixtures.ExpiringPersonDifferentTimeUnit; | ||
import com.redis.om.spring.annotations.document.fixtures.ExpiringPersonDifferentTimeUnitRepository; | ||
import com.redis.om.spring.annotations.document.fixtures.ExpiringPersonRepository; | ||
import com.redis.om.spring.annotations.document.fixtures.ExpiringPersonWithDefault; | ||
import com.redis.om.spring.annotations.document.fixtures.ExpiringPersonWithDefaultRepository; | ||
|
||
public class DocumentTTLTests extends AbstractBaseDocumentTest { | ||
@Autowired | ||
ExpiringPersonWithDefaultRepository withDefaultrepository; | ||
|
||
@Autowired | ||
ExpiringPersonRepository withTTLAnnotationRepository; | ||
|
||
@Autowired | ||
ExpiringPersonDifferentTimeUnitRepository withTTLwTimeUnitAnnotationRepository; | ||
|
||
@Autowired | ||
RedisTemplate<String, String> template; | ||
|
||
@BeforeEach | ||
public void cleanUp() { | ||
withDefaultrepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
void testClassLevelDefaultTTL() { | ||
ExpiringPersonWithDefault gordon = ExpiringPersonWithDefault.of("Gordon Welchman"); | ||
withDefaultrepository.save(gordon); | ||
|
||
Long expire = withDefaultrepository.getExpiration(gordon.getId()); | ||
|
||
assertThat(expire).isEqualTo(5L); | ||
} | ||
|
||
@Test | ||
void testTimeToLiveAnnotation() { | ||
ExpiringPerson mWoodger = ExpiringPerson.of("Mike Woodger", 15L); | ||
withTTLAnnotationRepository.save(mWoodger); | ||
|
||
Long expire = withTTLAnnotationRepository.getExpiration(mWoodger.getId()); | ||
|
||
assertThat(expire).isEqualTo(15L); | ||
} | ||
|
||
@Test | ||
void testTimeToLiveAnnotationWithDifferentTimeUnit() { | ||
ExpiringPersonDifferentTimeUnit jWilkinson = ExpiringPersonDifferentTimeUnit.of("Jim Wilkinson", 7L); | ||
withTTLwTimeUnitAnnotationRepository.save(jWilkinson); | ||
|
||
Long expire = withTTLwTimeUnitAnnotationRepository.getExpiration(jWilkinson.getId()); | ||
|
||
assertThat(expire).isEqualTo(7L*24*60*60); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...pring/src/test/java/com/redis/om/spring/annotations/document/fixtures/ExpiringPerson.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,24 @@ | ||
package com.redis.om.spring.annotations.document.fixtures; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
import com.redis.om.spring.annotations.Document; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@RequiredArgsConstructor(staticName = "of") | ||
@Document(timeToLive = 5) | ||
public class ExpiringPerson { | ||
@Id String id; | ||
@NonNull | ||
String name; | ||
|
||
@NonNull | ||
@TimeToLive Long ttl; | ||
} |
26 changes: 26 additions & 0 deletions
26
...va/com/redis/om/spring/annotations/document/fixtures/ExpiringPersonDifferentTimeUnit.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,26 @@ | ||
package com.redis.om.spring.annotations.document.fixtures; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
import com.redis.om.spring.annotations.Document; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@RequiredArgsConstructor(staticName = "of") | ||
@Document(timeToLive = 5) | ||
public class ExpiringPersonDifferentTimeUnit { | ||
@Id String id; | ||
@NonNull | ||
String name; | ||
|
||
@NonNull | ||
@TimeToLive(unit = TimeUnit.DAYS) Long ttl; | ||
} |
6 changes: 6 additions & 0 deletions
6
...is/om/spring/annotations/document/fixtures/ExpiringPersonDifferentTimeUnitRepository.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,6 @@ | ||
package com.redis.om.spring.annotations.document.fixtures; | ||
|
||
import com.redis.om.spring.repository.RedisDocumentRepository; | ||
|
||
public interface ExpiringPersonDifferentTimeUnitRepository extends RedisDocumentRepository<ExpiringPersonDifferentTimeUnit, String> { | ||
} |
6 changes: 6 additions & 0 deletions
6
...test/java/com/redis/om/spring/annotations/document/fixtures/ExpiringPersonRepository.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,6 @@ | ||
package com.redis.om.spring.annotations.document.fixtures; | ||
|
||
import com.redis.om.spring.repository.RedisDocumentRepository; | ||
|
||
public interface ExpiringPersonRepository extends RedisDocumentRepository<ExpiringPerson, String> { | ||
} |
20 changes: 20 additions & 0 deletions
20
...est/java/com/redis/om/spring/annotations/document/fixtures/ExpiringPersonWithDefault.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,20 @@ | ||
package com.redis.om.spring.annotations.document.fixtures; | ||
|
||
import org.springframework.data.annotation.Id; | ||
|
||
import com.redis.om.spring.annotations.Document; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@RequiredArgsConstructor(staticName = "of") | ||
@Document(timeToLive = 5) | ||
public class ExpiringPersonWithDefault { | ||
@Id String id; | ||
@NonNull | ||
String name; | ||
} |
6 changes: 6 additions & 0 deletions
6
...om/redis/om/spring/annotations/document/fixtures/ExpiringPersonWithDefaultRepository.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,6 @@ | ||
package com.redis.om.spring.annotations.document.fixtures; | ||
|
||
import com.redis.om.spring.repository.RedisDocumentRepository; | ||
|
||
public interface ExpiringPersonWithDefaultRepository extends RedisDocumentRepository<ExpiringPersonWithDefault, String> { | ||
} |
Oops, something went wrong.