DATAREDIS-271 - Add support for 'pSetEx'.

Support for 'pSetEx' has been added for 'jedis' & 'srp'.
For 'lettuce' the command is emulated using 'eval'.

There is no support for 'pSetEx' when using 'jredis'.

'DefaultValueOperations.set' used with 'TimeUnit.MILLISECONDS' will fallback to 'setEx' in case 'pSetEx' is not supported by the driver in use.

Original pull request: #46.
This commit is contained in:
Christoph Strobl
2014-03-13 15:21:45 +01:00
committed by Thomas Darimont
parent a3ac8d0899
commit 4b2ccbecb9
18 changed files with 244 additions and 11 deletions

View File

@@ -66,6 +66,7 @@ import org.springframework.test.annotation.ProfileValueSourceConfiguration;
* @author Costin Leau
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Thomas Darimont
*/
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
public abstract class AbstractConnectionIntegrationTests {
@@ -359,6 +360,20 @@ public abstract class AbstractConnectionIntegrationTests {
assertTrue(waitFor(new KeyExpired("expy"), 2500l));
}
/**
* @see DATAREDIS-271
*/
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testPsetEx() throws Exception {
connection.pSetEx("expy", 500L, "yep");
actual.add(connection.get("expy"));
verifyResults(Arrays.asList(new Object[] { "yep" }));
assertTrue(waitFor(new KeyExpired("expy"), 2500L));
}
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testBRPopTimeout() throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* Unit test of {@link DefaultStringRedisConnection}
*
* @author Jennifer Hickey
* @auhtor Christoph Strobl
*/
public class DefaultStringRedisConnectionTests {
@@ -907,6 +908,16 @@ public class DefaultStringRedisConnectionTests {
verifyResults(Arrays.asList(new Object[] { true }));
}
/**
* @see DATAREDIS-271
*/
@Test
public void testPSetExShouldDelegateCallToNativeConnection() {
connection.pSetEx(fooBytes, 10L, barBytes);
verify(nativeConnection, times(1)).pSetEx(eq(fooBytes), eq(10L), eq(barBytes));
}
@Test
public void testSInterBytes() {
doReturn(bytesSet).when(nativeConnection).sInter(fooBytes, barBytes);

View File

@@ -801,4 +801,12 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
IsCollectionContaining.hasItems("awesome".getBytes(), "cool".getBytes(),
"supercalifragilisticexpialidocious".getBytes()));
}
/**
* @see DATAREDIS-271
*/
@Test(expected = UnsupportedOperationException.class)
public void testPsetEx() throws Exception {
super.testPsetEx();
}
}

View File

@@ -287,6 +287,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
@SuppressWarnings("unchecked")
@Test
public void testExecuteShouldConvertArrayReplyCorrectly() {
connection.set("spring", "awesome");
connection.set("data", "cool");
connection.set("redis", "supercalifragilisticexpialidocious");

View File

@@ -112,4 +112,5 @@ public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectio
factory2.destroy();
}
}
}

View File

@@ -82,4 +82,5 @@ public class LettuceConnectionPipelineTxIntegrationTests extends LettuceConnecti
// Return exec results and this test should behave exactly like its superclass
return txResults;
}
}

View File

@@ -75,4 +75,5 @@ public class LettuceConnectionTransactionIntegrationTests extends AbstractConnec
public void testSelect() {
super.testSelect();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ import org.springframework.data.redis.connection.RedisConnection;
* Integration test of {@link DefaultValueOperations}
*
* @author Jennifer Hickey
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
public class DefaultValueOperationsTests<K, V> {
@@ -173,7 +174,23 @@ public class DefaultValueOperationsTests<K, V> {
@Test
public void testSetWithExpiration() {
// 1 ms timeout gets upgraded to 1 sec timeout at the moment
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
final K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
valueOps.set(key1, value1, 1, TimeUnit.SECONDS);
waitFor(new TestCondition() {
public boolean passes() {
return (!redisTemplate.hasKey(key1));
}
}, 1000);
}
/**
* @see DATAREDIS-271
*/
@Test
public void testSetWithExpirationWithTimeUnitMilliseconds() {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
final K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -182,7 +199,7 @@ public class DefaultValueOperationsTests<K, V> {
public boolean passes() {
return (!redisTemplate.hasKey(key1));
}
}, 1000);
}, 500);
}
@Test