DATAREDIS-286 - Avoid overflow in JedisConnection#expire / #pexpire.
Workaround Jedis issue https://github.com/xetorthio/jedis/pull/575. We now delegate calls to expire(...) to pExpireAt(...) in case the seconds parameter is > than Integer.MAX_VALUE. We query the server time to compute the new expiration date. Original pull request: #52.
This commit is contained in:
committed by
Christoph Strobl
parent
408b52a449
commit
59582f1910
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -333,4 +334,35 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
|
||||
AllOf.allOf(IsInstanceOf.instanceOf(List.class), IsCollectionContaining.hasItems("awesome".getBytes(),
|
||||
"cool".getBytes(), "supercalifragilisticexpialidocious".getBytes())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-286
|
||||
*/
|
||||
@Test
|
||||
public void expireShouldSupportExiprationForValuesLargerThanInteger() {
|
||||
|
||||
connection.set("expireKey", "foo");
|
||||
|
||||
long seconds = ((long) Integer.MAX_VALUE) + 1;
|
||||
connection.expire("expireKey", seconds);
|
||||
long ttl = connection.ttl("expireKey");
|
||||
|
||||
assertThat(ttl, is(seconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-286
|
||||
*/
|
||||
@Test
|
||||
public void pExpireShouldSupportExiprationForValuesLargerThanInteger() {
|
||||
|
||||
connection.set("pexpireKey", "foo");
|
||||
|
||||
long millis = ((long) Integer.MAX_VALUE) + 10;
|
||||
connection.pExpire("pexpireKey", millis);
|
||||
long ttl = connection.pTtl("pexpireKey");
|
||||
|
||||
assertTrue(String.format("difference between millis=%s and ttl=%s should not be greater than 20ms but is %s",
|
||||
millis, ttl, millis - ttl), millis - ttl < 20L);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user