DATAREDIS-716 - Add support for OBJECT REFCOUNT, ENCODING and IDLETIME.

Original pull request: #337.
This commit is contained in:
Christoph Strobl
2018-04-30 14:07:06 +02:00
committed by Mark Paluch
parent f8d63f4736
commit 70a3e5dbe7
14 changed files with 688 additions and 19 deletions

View File

@@ -27,6 +27,7 @@ import static org.springframework.data.redis.connection.RedisGeoCommands.Distanc
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
import static org.springframework.data.redis.core.ScanOptions.*;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CountDownLatch;
@@ -64,6 +65,7 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.SortParameters.Order;
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
@@ -2804,8 +2806,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.hStrLen("hash-no-exist", "key-2"));
verifyResults(
Arrays.asList(new Object[] { 0L }));
verifyResults(Arrays.asList(new Object[] { 0L }));
}
@Test // DATAREDIS-694
@@ -2846,6 +2847,61 @@ public abstract class AbstractConnectionIntegrationTests {
verifyResults(Arrays.asList(new Object[] { true, 16L }));
}
@Test // DATAREDIS-716
public void encodingReturnsCorrectly() {
actual.add(connection.set("encode.this", "1000"));
actual.add(connection.encodingOf("encode.this"));
verifyResults(Arrays.asList(new Object[] { true, RedisValueEncoding.INT }));
}
@Test // DATAREDIS-716
public void encodingReturnsVacantWhenKeyDoesNotExist() {
actual.add(connection.encodingOf("encode.this"));
verifyResults(Arrays.asList(new Object[] { RedisValueEncoding.VACANT }));
}
@Test // DATAREDIS-716
public void idletimeReturnsCorrectly() {
actual.add(connection.set("idle.this", "1000"));
actual.add(connection.get("idle.this"));
actual.add(connection.idletime("idle.this"));
verifyResults(Arrays.asList(new Object[] { true, "1000", Duration.ofSeconds(0) }));
}
@Test // DATAREDIS-716
public void idldetimeReturnsNullWhenKeyDoesNotExist() {
actual.add(connection.idletime("idle.this"));
verifyResults(Arrays.asList(new Object[] { null }));
}
@Test // DATAREDIS-716
public void refcountReturnsCorrectly() {
actual.add(connection.lPush("refcount.this", "1000"));
actual.add(connection.refcount("refcount.this"));
verifyResults(Arrays.asList(new Object[] { 1L, 1L }));
}
@Test // DATAREDIS-716
public void refcountReturnsNullWhenKeyDoesNotExist() {
actual.add(connection.refcount("refcount.this"));
verifyResults(Arrays.asList(new Object[] { null }));
}
protected void verifyResults(List<Object> expected) {
assertEquals(expected, getResults());
}

View File

@@ -37,6 +37,7 @@ import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
@@ -189,9 +190,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
Flux<List<ByteBuffer>> input = Flux.just(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER),
Collections.singletonList(KEY_1_BBUFFER));
Flux<Long> result = connection.keyCommands()
.mDel(input)
.map(NumericResponse::getOutput);
Flux<Long> result = connection.keyCommands().mDel(input).map(NumericResponse::getOutput);
StepVerifier.create(result).expectNextCount(2).verifyComplete();
}
@@ -240,9 +239,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
Flux<List<ByteBuffer>> input = Flux.just(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER),
Collections.singletonList(KEY_1_BBUFFER));
Flux<Long> result = connection.keyCommands()
.mUnlink(input)
.map(NumericResponse::getOutput);
Flux<Long> result = connection.keyCommands().mUnlink(input).map(NumericResponse::getOutput);
StepVerifier.create(result).expectNextCount(2).verifyComplete();
}
@@ -374,4 +371,48 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.expectNext(0L) //
.verifyComplete();
}
@Test // DATAREDIS-716
public void encodingReturnsCorrectly() {
nativeCommands.set(KEY_1, "1000");
connection.keyCommands().encodingOf(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(RedisValueEncoding.INT)
.verifyComplete();
}
@Test // DATAREDIS-716
public void encodingReturnsVacantWhenKeyDoesNotExist() {
connection.keyCommands().encodingOf(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(RedisValueEncoding.VACANT)
.verifyComplete();
}
@Test // DATAREDIS-716
public void idletimeReturnsCorrectly() {
nativeCommands.set(KEY_1, "1000");
nativeCommands.get(KEY_1);
connection.keyCommands().idletime(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(Duration.ofSeconds(0))
.verifyComplete();
}
@Test // DATAREDIS-716
public void idldetimeReturnsNullWhenKeyDoesNotExist() {
connection.keyCommands().idletime(KEY_1_BBUFFER).as(StepVerifier::create).verifyComplete();
}
@Test // DATAREDIS-716
public void refcountReturnsCorrectly() {
nativeCommands.lpush(KEY_1, "1000");
connection.keyCommands().refcount(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-716
public void refcountReturnsNullWhenKeyDoesNotExist() {
connection.keyCommands().refcount(KEY_1_BBUFFER).as(StepVerifier::create).verifyComplete();
}
}