DATAREDIS-782 - Add support for SET key value NX EX max-lock-time.
We now expose ValueOperations.setIfAbsent(…) to set values when absent along their expiry. Original pull request: #320.
This commit is contained in:
committed by
Mark Paluch
parent
567fa43e60
commit
a2ed8e1d9b
@@ -18,6 +18,7 @@ package org.springframework.data.redis.core;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -135,6 +136,24 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
|
||||
StepVerifier.create(valueOperations.setIfAbsent(key, value)).expectNext(false).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-782
|
||||
public void setIfAbsentWithExpiry() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
V value = valueFactory.instance();
|
||||
|
||||
StepVerifier.create(valueOperations.setIfAbsent(key, value, Duration.ofMillis(500))).expectNext(true)
|
||||
.expectComplete().verify();
|
||||
|
||||
StepVerifier.create(valueOperations.setIfAbsent(key, value)).expectNext(false).verifyComplete();
|
||||
StepVerifier.create(valueOperations.setIfAbsent(key, value, Duration.ofMillis(500))).expectNext(false)
|
||||
.verifyComplete();
|
||||
|
||||
Mono<Boolean> mono = valueOperations.setIfAbsent(key, value, Duration.ofMillis(500))
|
||||
.delaySubscription(Duration.ofMillis(500));
|
||||
StepVerifier.create(mono).expectNext(true).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-602, DATAREDIS-779
|
||||
public void setIfPresent() {
|
||||
|
||||
|
||||
@@ -235,6 +235,17 @@ public class DefaultValueOperationsTests<K, V> {
|
||||
assertFalse(valueOps.setIfAbsent(key1, value2));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-782
|
||||
public void testSetIfAbsentWithExpiration() {
|
||||
final K key1 = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
V value2 = valueFactory.instance();
|
||||
assertTrue(valueOps.setIfAbsent(key1, value1, 500, TimeUnit.MILLISECONDS));
|
||||
assertFalse(valueOps.setIfAbsent(key1, value2));
|
||||
assertFalse(valueOps.setIfAbsent(key1, value2, 500, TimeUnit.MILLISECONDS));
|
||||
waitFor(() -> (valueOps.setIfAbsent(key1, value1, 500, TimeUnit.MILLISECONDS)), 500);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSize() {
|
||||
K key1 = keyFactory.instance();
|
||||
|
||||
Reference in New Issue
Block a user