Merge branch 'master' of github.com:redisson/redisson

pull/2247/head^2 redisson-3.11.1
Nikita Koksharov 6 years ago
commit fa0d64dae8

@ -1595,6 +1595,9 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
"local t, val = struct.unpack('dLc0', v); " +
"if t ~= 0 then " +
" local expireIdle = redis.call('zscore', KEYS[3], ARGV[2]); " +
" if tonumber(expireIdle) > tonumber(ARGV[1]) then " +
" redis.call('zadd', KEYS[3], t + tonumber(ARGV[1]), ARGV[2]); " +
" end ;" +
" if expireIdle ~= false then " +
" expireDate = math.min(expireDate, tonumber(expireIdle)) " +
" end; " +
@ -1627,6 +1630,9 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
"end; " +
"if t ~= 0 then " +
" local expireIdle = redis.call('zscore', KEYS[3], ARGV[2]); " +
" if tonumber(expireIdle) > tonumber(ARGV[1]) then " +
" redis.call('zadd', KEYS[3], t + tonumber(ARGV[1]), ARGV[2]); " +
" end ;" +
" if expireIdle ~= false then " +
" expireDate = math.min(expireDate, tonumber(expireIdle)) " +
" end; " +
@ -1658,6 +1664,9 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
"end; " +
"if t ~= 0 then " +
" local expireIdle = redis.call('zscore', KEYS[3], ARGV[2]); " +
" if tonumber(expireIdle) > tonumber(ARGV[1]) then " +
" redis.call('zadd', KEYS[3], t + tonumber(ARGV[1]), ARGV[2]); " +
" end ;" +
" if expireIdle ~= false then " +
" expireDate = math.min(expireDate, tonumber(expireIdle)) " +
" end; " +

@ -644,6 +644,39 @@ public class RedissonMapCacheTest extends BaseMapTest {
map.destroy();
}
@Test
public void testReplaceValueTTLIdleUpdate() throws InterruptedException {
RMapCache<SimpleKey, SimpleValue> map = null;
SimpleValue val1;
try {
map = redisson.getMapCache("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"), 2, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
Thread.sleep(750);
// update value, would like idle timeout to be refreshed
SimpleValue res = map.replace(new SimpleKey("1"), new SimpleValue("3"));
assertThat(res).isNotNull();
Thread.sleep(750);
// if idle timeout has been updated val1 will be not be null, else it will be null
val1 = map.get(new SimpleKey("1"));
assertThat(val1).isNotNull();
Thread.sleep(750);
// val1 will have expired due to TTL
val1 = map.get(new SimpleKey("1"));
assertThat(val1).isNull();
} catch (Exception e) {
e.printStackTrace();
} finally {
map.remove(new SimpleKey("1"));
}
}
@Test
public void testScheduler() throws InterruptedException {
RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple3");

Loading…
Cancel
Save