diff --git a/redisson/src/main/java/org/redisson/RedissonMapCache.java b/redisson/src/main/java/org/redisson/RedissonMapCache.java
index 6f9b9910f..ef56a5a6f 100644
--- a/redisson/src/main/java/org/redisson/RedissonMapCache.java
+++ b/redisson/src/main/java/org/redisson/RedissonMapCache.java
@@ -15,8 +15,16 @@
*/
package org.redisson;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.FutureListener;
+import java.math.BigDecimal;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
import org.redisson.api.MapOptions;
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
@@ -50,15 +58,8 @@ import org.redisson.command.CommandAsyncExecutor;
import org.redisson.connection.decoder.MapGetAllDecoder;
import org.redisson.eviction.EvictionScheduler;
-import java.math.BigDecimal;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.FutureListener;
/**
*
Map-based cache with ability to set TTL for each entry via
@@ -81,161 +82,134 @@ import java.util.concurrent.TimeUnit;
*/
public class RedissonMapCache extends RedissonMap implements RMapCache {
- private final int maxSize;
-
- public RedissonMapCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor commandExecutor,
- String name, RedissonClient redisson, MapOptions options) {
+ public RedissonMapCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor commandExecutor,
+ String name, RedissonClient redisson, MapOptions options) {
super(commandExecutor, name, redisson, options);
evictionScheduler.schedule(getName(), getTimeoutSetName(), getIdleSetName(), getExpiredChannelName());
-
- if (options != null) {
- this.maxSize = options.getMaxSize();
- } else {
- this.maxSize = 0;
- }
}
- public RedissonMapCache(Codec codec, EvictionScheduler evictionScheduler, CommandAsyncExecutor commandExecutor,
- String name, RedissonClient redisson, MapOptions options) {
+ public RedissonMapCache(Codec codec, EvictionScheduler evictionScheduler, CommandAsyncExecutor commandExecutor,
+ String name, RedissonClient redisson, MapOptions options) {
super(codec, commandExecutor, name, redisson, options);
evictionScheduler.schedule(getName(), getTimeoutSetName(), getIdleSetName(), getExpiredChannelName());
-
- if (options != null) {
- this.maxSize = options.getMaxSize();
- } else {
- this.maxSize = 0;
- }
}
-
+
@Override
public RFuture containsKeyAsync(Object key) {
checkKey(key);
-
+
return commandExecutor.evalWriteAsync(getName(key), codec, RedisCommands.EVAL_BOOLEAN,
- "local value = redis.call('hget', KEYS[1], ARGV[2]);" +
- "local expireDate = 92233720368547758;" +
- "if value ~= false then" +
- " local maxSize = tonumber(ARGV[3]);" +
- " if maxSize ~= 0 then" +
- " redis.call('zadd', KEYS[4], tonumber(ARGV[1]), ARGV[2]);" +
- " end;" +
- " local expireDateScore = redis.call('zscore', KEYS[2], ARGV[2]);" +
- " if expireDateScore ~= false then" +
- " expireDate = tonumber(expireDateScore)" +
- " end;" +
- " local t, val = struct.unpack('dLc0', value);" +
- " if t ~= 0 then" +
- " local expireIdle = redis.call('zscore', KEYS[3], ARGV[2]);" +
- " if expireIdle ~= false then" +
- " if tonumber(expireIdle) > tonumber(ARGV[1]) then" +
- " local value = struct.pack('dLc0', t, string.len(val), val);" +
- " redis.call('hset', KEYS[1], ARGV[2], value);" +
- " redis.call('zadd', KEYS[3], t + tonumber(ARGV[1]), ARGV[2]);" +
- " end;" +
- " expireDate = math.min(expireDate, tonumber(expireIdle))" +
- " end;" +
- " end;" +
- " if expireDate <= tonumber(ARGV[1]) then" +
- " return 0;" +
- " end;" +
- " return 1;" +
+ "local value = redis.call('hget', KEYS[1], ARGV[2]); " +
+ "local expireDate = 92233720368547758; " +
+ "if value ~= false then " +
+ "local expireDateScore = redis.call('zscore', KEYS[2], ARGV[2]); "
+ + "if expireDateScore ~= false then "
+ + "expireDate = tonumber(expireDateScore) "
+ + "end; "
+ + "local t, val = struct.unpack('dLc0', value); "
+ + "if t ~= 0 then "
+ + "local expireIdle = redis.call('zscore', KEYS[3], ARGV[2]); "
+ + "if expireIdle ~= false then "
+ + "if tonumber(expireIdle) > tonumber(ARGV[1]) then "
+ + "local value = struct.pack('dLc0', t, string.len(val), val); "
+ + "redis.call('hset', KEYS[1], ARGV[2], value); "
+ + "redis.call('zadd', KEYS[3], t + tonumber(ARGV[1]), ARGV[2]); "
+ + "end; "
+ + "expireDate = math.min(expireDate, tonumber(expireIdle)) "
+ + "end; "
+ + "end; "
+ + "if expireDate <= tonumber(ARGV[1]) then "
+ + "return 0;"
+ + "end; "
+ + "return 1;" +
"end;" +
"return 0; ",
- Arrays.