DATAREDIS-1103 - Polishing.

Move keepTTL to Expiration and remove superfluous methods from interfaces. Add tests for reactive variant and work around an open issue in Jedis to support KEEPTTL though the API does not offer that option directly.

Original Pull Request: #562
This commit is contained in:
Christoph Strobl
2020-10-08 08:30:02 +02:00
parent 232c8a5dd4
commit 0f54fcf796
14 changed files with 117 additions and 98 deletions

View File

@@ -179,6 +179,20 @@ public abstract class AbstractConnectionIntegrationTests {
assertThat(waitFor(new KeyExpired("exp"), 3000l)).isTrue();
}
@Test // DATAREDIS-1103
public void testSetWithKeepTTL() {
actual.add(connection.set("exp", "true"));
actual.add(connection.expire("exp", 10));
actual.add(connection.set("exp", "changed", Expiration.keepTtl(), SetOption.upsert()));
actual.add(connection.ttl("exp"));
List<Object> results = getResults();
assertThat(results.get(2)).isEqualTo(true);
assertThat((Long) results.get(3)).isCloseTo(10L, Offset.offset(5L));
}
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testExpireAt() throws Exception {

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Offset.offset;
import static org.springframework.data.redis.connection.BitFieldSubCommands.*;
import static org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldIncrBy.Overflow.*;
@@ -37,12 +36,12 @@ import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeUnit;
import org.assertj.core.data.Offset;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Range.Bound;
import org.springframework.data.geo.Circle;
@@ -2472,14 +2471,13 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
public void setKeepTTL() {
long expireSeconds = 10;
assertThat(clusterConnection.setEx(KEY_1_BYTES, expireSeconds, VALUE_2_BYTES));
nativeConnection.setex(KEY_1, expireSeconds, VALUE_1);
assertThat(clusterConnection.get(KEY_1_BYTES)).isEqualTo(VALUE_2_BYTES);
assertThat(
clusterConnection.stringCommands().set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.keepTtl(), SetOption.upsert()))
.isTrue();
assertThat(clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.persistent(), SetOption.upsert(), true));
long ttl = clusterConnection.ttl(KEY_1_BYTES);
assertThat(0 < ttl && ttl <= expireSeconds);
assertThat(nativeConnection.ttl(KEY_1)).isCloseTo(expireSeconds, Offset.offset(5L));
assertThat(nativeConnection.get(KEY_1)).isEqualTo(VALUE_2);
}
}

View File

@@ -37,8 +37,8 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.assertj.core.data.Offset;
import org.junit.Test;
import org.springframework.data.domain.Range;
import org.springframework.data.domain.Range.Bound;
import org.springframework.data.redis.connection.ReactiveRedisConnection;
@@ -49,6 +49,7 @@ import org.springframework.data.redis.connection.ReactiveRedisConnection.MultiVa
import org.springframework.data.redis.connection.ReactiveRedisConnection.RangeCommand;
import org.springframework.data.redis.connection.ReactiveStringCommands.SetCommand;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.test.util.HexStringUtils;
import org.springframework.data.redis.util.ByteUtils;
@@ -509,4 +510,18 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(16L).verifyComplete();
}
@Test // DATAREDIS-1103
public void setKeepTTL() {
long expireSeconds = 10;
nativeCommands.setex(KEY_1, expireSeconds, VALUE_1);
connection.stringCommands().set(KEY_1_BBUFFER, VALUE_2_BBUFFER, Expiration.keepTtl(), SetOption.upsert())
.as(StepVerifier::create) //
.expectNext(true) //
.verifyComplete();
assertThat(nativeBinaryCommands.ttl(KEY_1_BBUFFER)).isCloseTo(expireSeconds, Offset.offset(5L));
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_2);
}
}