Skip to content

Commit

Permalink
Merge branch 'master' of github.com:redisson/redisson
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Koksharov committed Jun 25, 2019
2 parents ef033d8 + bc2af1e commit fa0d64d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions redisson/src/main/java/org/redisson/RedissonMapCache.java
Expand Up @@ -1595,6 +1595,9 @@ protected RFuture<Boolean> replaceOperationAsync(K key, V oldValue, V newValue)
"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; " +
Expand Down Expand Up @@ -1627,6 +1630,9 @@ protected RFuture<Boolean> fastReplaceOperationAsync(K key, V value) {
"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; " +
Expand Down Expand Up @@ -1658,6 +1664,9 @@ protected RFuture<V> replaceOperationAsync(K key, V value) {
"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; " +
Expand Down
33 changes: 33 additions & 0 deletions redisson/src/test/java/org/redisson/RedissonMapCacheTest.java
Expand Up @@ -644,6 +644,39 @@ public void testReplaceValueTTL() throws InterruptedException {
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");
Expand Down

0 comments on commit fa0d64d

Please sign in to comment.