Add Redis 2.6 millisecond expiration commands

DATAREDIS-178

Add pExpire, pExpireAt, pTTl ops to connections
This commit is contained in:
Jennifer Hickey
2013-06-12 14:03:00 -07:00
parent 80ac1af812
commit a4f3d7db44
14 changed files with 343 additions and 1 deletions

View File

@@ -114,6 +114,30 @@ public abstract class AbstractConnectionIntegrationTests {
assertTrue(waitFor(new KeyExpired("exp2"), 3000l));
}
@Test
public void testPExpire() {
connection.set("exp", "true");
assertTrue(connection.pExpire("exp", 100));
assertTrue(waitFor(new KeyExpired("exp"), 300l));
}
@Test
public void testPExpireKeyNotExists() {
assertFalse(connection.pExpire("nonexistent", 100));
}
@Test
public void testPExpireAt() {
connection.set("exp", "true");
assertTrue(connection.pExpireAt("exp", System.currentTimeMillis() + 200));
assertTrue(waitFor(new KeyExpired("exp"), 600l));
}
@Test
public void testPExpireAtKeyNotExists() {
assertFalse(connection.pExpireAt("nonexistent", System.currentTimeMillis() + 200));
}
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testPersist() throws Exception {
@@ -517,6 +541,20 @@ public abstract class AbstractConnectionIntegrationTests {
verifyResults(Arrays.asList(new Object[] { -1L }), actual);
}
@Test
public void testPTtlNoExpire() {
connection.set("whatup", "yo");
actual.add(connection.pTtl("whatup"));
verifyResults(Arrays.asList(new Object[] { -1L }), actual);
}
@Test
public void testPTtl() {
connection.set("whatup", "yo");
connection.pExpire("whatup", 9000l);
assertTrue(connection.pTtl("whatup") > -1);
}
@Test
public void testType() {
connection.set("something", "yo");

View File

@@ -115,6 +115,46 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends
verifyResults(Arrays.asList(new Object[] { "bar" }), actual);
}
@Test
public void testPExpire() {
connection.set("exp", "true");
actual.add(connection.pExpire("exp", 100));
verifyResults(Arrays.asList(new Object[] { 1l }), actual);
assertTrue(waitFor(new KeyExpired("exp"), 1000l));
}
@Test
public void testPExpireKeyNotExists() {
actual.add(connection.pExpire("nonexistent", 100));
verifyResults(Arrays.asList(new Object[] { 0l }), actual);
}
@Test
public void testPExpireAt() {
connection.set("exp2", "true");
actual.add(connection.pExpireAt("exp2", System.currentTimeMillis() + 200));
verifyResults(Arrays.asList(new Object[] { 1l }), actual);
assertTrue(waitFor(new KeyExpired("exp2"), 1000l));
}
@Test
public void testPExpireAtKeyNotExists() {
actual.add(connection.pExpireAt("nonexistent", System.currentTimeMillis() + 200));
verifyResults(Arrays.asList(new Object[] { 0l }), actual);
}
@Test
public void testPTtl() {
connection.set("whatup", "yo");
actual.add(connection.pExpire("whatup", 9000l));
verifyResults(Arrays.asList(new Object[] { 1l }), actual);
assertTrue(waitFor(new TestCondition() {
public boolean passes() {
return (connection.pTtl("whatup") > -1);
}
}, 1000l));
}
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testExpire() throws Exception {

View File

@@ -50,6 +50,36 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
connection = null;
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpire() {
super.testPExpire();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireKeyNotExists() {
super.testPExpireKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireAt() {
super.testPExpireAt();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireAtKeyNotExists() {
super.testPExpireAtKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
public void testPTtl() {
super.testPTtl();
}
@Test(expected=UnsupportedOperationException.class)
public void testPTtlNoExpire() {
super.testPTtlNoExpire();
}
@Test
public void testIncrDecrByLong() {
String key = "test.count";

View File

@@ -92,6 +92,36 @@ public class JedisConnectionPipelineIntegrationTests extends
}
// Unsupported Ops
@Test(expected=UnsupportedOperationException.class)
public void testPExpire() {
super.testPExpire();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireKeyNotExists() {
super.testPExpireKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireAt() {
super.testPExpireAt();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireAtKeyNotExists() {
super.testPExpireAtKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
public void testPTtl() {
super.testPTtl();
}
@Test(expected=UnsupportedOperationException.class)
public void testPTtlNoExpire() {
super.testPTtlNoExpire();
}
@Test(expected = RedisSystemException.class)
public void testBitSet() throws Exception {
super.testBitSet();

View File

@@ -288,6 +288,36 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
super.testZRevRangeByScoreWithScoresOffsetCount();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpire() {
super.testPExpire();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireKeyNotExists() {
super.testPExpireKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireAt() {
super.testPExpireAt();
}
@Test(expected=UnsupportedOperationException.class)
public void testPExpireAtKeyNotExists() {
super.testPExpireAtKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
public void testPTtl() {
super.testPTtl();
}
@Test(expected=UnsupportedOperationException.class)
public void testPTtlNoExpire() {
super.testPTtlNoExpire();
}
// Jredis returns null for rPush
@Test
public void testSort() {

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.connection.lettuce;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -292,6 +291,46 @@ public class LettuceConnectionPipelineIntegrationTests extends
assertTrue(waitFor(new KeyExpired("exp"), 2500));
}
@Test
public void testPExpire() {
connection.set("exp", "true");
actual.add(connection.pExpire("exp", 100));
verifyResults(Arrays.asList(new Object[] { true }), actual);
assertTrue(waitFor(new KeyExpired("exp"), 1000l));
}
@Test
public void testPExpireKeyNotExists() {
actual.add(connection.pExpire("nonexistent", 100));
verifyResults(Arrays.asList(new Object[] { false }), actual);
}
@Test
public void testPExpireAt() {
connection.set("exp2", "true");
actual.add(connection.pExpireAt("exp2", System.currentTimeMillis() + 200));
verifyResults(Arrays.asList(new Object[] { true }), actual);
assertTrue(waitFor(new KeyExpired("exp2"), 1000l));
}
@Test
public void testPExpireAtKeyNotExists() {
actual.add(connection.pExpireAt("nonexistent", System.currentTimeMillis() + 200));
verifyResults(Arrays.asList(new Object[] { false }), actual);
}
@Test
public void testPTtl() {
connection.set("whatup", "yo");
actual.add(connection.pExpire("whatup", 9000l));
verifyResults(Arrays.asList(new Object[] { true }), actual);
assertTrue(waitFor(new TestCondition() {
public boolean passes() {
return (connection.pTtl("whatup") > -1);
}
}, 1000l));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object convertResult(Object result) {
Object convertedResult = super.convertResult(result);