|
|
|
@ -66,13 +66,21 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
|
|
|
|
|
private final EvictionScheduler evictionScheduler;
|
|
|
|
|
protected String publishCommand;
|
|
|
|
|
private String timeoutSetName;
|
|
|
|
|
private String idleSetName;
|
|
|
|
|
private String lastAccessTimeSetName;
|
|
|
|
|
private String optionsName;
|
|
|
|
|
|
|
|
|
|
public RedissonMapCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor commandExecutor,
|
|
|
|
|
String name, RedissonClient redisson, MapCacheOptions<K, V> options, WriteBehindService writeBehindService) {
|
|
|
|
|
super(commandExecutor, name, redisson, options, writeBehindService);
|
|
|
|
|
this.timeoutSetName = getTimeoutSetName(getRawName());
|
|
|
|
|
this.idleSetName = getIdleSetName(getRawName());
|
|
|
|
|
this.lastAccessTimeSetName = getLastAccessTimeSetName(getRawName());
|
|
|
|
|
this.optionsName = getOptionsName(getRawName());
|
|
|
|
|
if (evictionScheduler != null) {
|
|
|
|
|
evictionScheduler.schedule(getRawName(), getTimeoutSetName(), getIdleSetName(),
|
|
|
|
|
getExpiredChannelName(), getLastAccessTimeSetName(), options,
|
|
|
|
|
evictionScheduler.schedule(getRawName(), timeoutSetName, idleSetName,
|
|
|
|
|
getExpiredChannelName(), lastAccessTimeSetName, options,
|
|
|
|
|
commandExecutor.getConnectionManager().getSubscribeService().getPublishCommand());
|
|
|
|
|
}
|
|
|
|
|
this.evictionScheduler = evictionScheduler;
|
|
|
|
@ -82,9 +90,13 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
public RedissonMapCache(Codec codec, EvictionScheduler evictionScheduler, CommandAsyncExecutor commandExecutor,
|
|
|
|
|
String name, RedissonClient redisson, MapCacheOptions<K, V> options, WriteBehindService writeBehindService) {
|
|
|
|
|
super(codec, commandExecutor, name, redisson, options, writeBehindService);
|
|
|
|
|
this.timeoutSetName = getTimeoutSetName(getRawName());
|
|
|
|
|
this.idleSetName = getIdleSetName(getRawName());
|
|
|
|
|
this.lastAccessTimeSetName = getLastAccessTimeSetName(getRawName());
|
|
|
|
|
this.optionsName = getOptionsName(getRawName());
|
|
|
|
|
if (evictionScheduler != null) {
|
|
|
|
|
evictionScheduler.schedule(getRawName(), getTimeoutSetName(), getIdleSetName(),
|
|
|
|
|
getExpiredChannelName(), getLastAccessTimeSetName(), options,
|
|
|
|
|
evictionScheduler.schedule(getRawName(), timeoutSetName, idleSetName,
|
|
|
|
|
getExpiredChannelName(), lastAccessTimeSetName, options,
|
|
|
|
|
commandExecutor.getConnectionManager().getSubscribeService().getPublishCommand());
|
|
|
|
|
}
|
|
|
|
|
this.evictionScheduler = evictionScheduler;
|
|
|
|
@ -113,7 +125,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
return commandExecutor.evalWriteNoRetryAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
|
"redis.call('hsetnx', KEYS[1], 'max-size', ARGV[1]);"
|
|
|
|
|
+ "return redis.call('hsetnx', KEYS[1], 'mode', ARGV[2]);",
|
|
|
|
|
Collections.singletonList(getOptionsName()), maxSize, mode);
|
|
|
|
|
Collections.singletonList(optionsName), maxSize, mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -136,7 +148,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Object> params = new ArrayList<>(3);
|
|
|
|
|
params.add(getOptionsName());
|
|
|
|
|
params.add(optionsName);
|
|
|
|
|
params.add("max-size");
|
|
|
|
|
params.add(maxSize);
|
|
|
|
|
params.add("mode");
|
|
|
|
@ -230,7 +242,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
" end;" +
|
|
|
|
|
"end;" +
|
|
|
|
|
"return 0;",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
System.currentTimeMillis(), encodeMapValue(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -283,7 +295,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
" end; " +
|
|
|
|
|
"end; " +
|
|
|
|
|
"return map;",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
args.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1326,8 +1338,8 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
|
|
|
|
|
"end;" +
|
|
|
|
|
"return counter;",
|
|
|
|
|
Arrays.asList(getRawName(), getTimeoutSetName(), getIdleSetName(),
|
|
|
|
|
getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.asList(getRawName(), timeoutSetName, idleSetName,
|
|
|
|
|
lastAccessTimeSetName, optionsName),
|
|
|
|
|
args.toArray());
|
|
|
|
|
return future;
|
|
|
|
|
}
|
|
|
|
@ -1422,8 +1434,8 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
|
|
|
|
|
"end;" +
|
|
|
|
|
"return counter;",
|
|
|
|
|
Arrays.asList(getRawName(), getTimeoutSetName(), getIdleSetName(),
|
|
|
|
|
getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.asList(getRawName(), timeoutSetName, idleSetName,
|
|
|
|
|
lastAccessTimeSetName, optionsName),
|
|
|
|
|
args.toArray());
|
|
|
|
|
return future;
|
|
|
|
|
}
|
|
|
|
@ -1688,7 +1700,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
" end; " +
|
|
|
|
|
"end; " +
|
|
|
|
|
"return map;",
|
|
|
|
|
Arrays.asList(getRawName(), getTimeoutSetName()),
|
|
|
|
|
Arrays.asList(getRawName(), timeoutSetName),
|
|
|
|
|
args.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1739,30 +1751,14 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
return prefixName("redisson__timeout__set", name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getTimeoutSetName() {
|
|
|
|
|
return prefixName("redisson__timeout__set", getRawName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getLastAccessTimeSetName(String name) {
|
|
|
|
|
return prefixName("redisson__map_cache__last_access__set", name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getLastAccessTimeSetName() {
|
|
|
|
|
return prefixName("redisson__map_cache__last_access__set", getRawName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getIdleSetName(String name) {
|
|
|
|
|
return prefixName("redisson__idle__set", name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getIdleSetName() {
|
|
|
|
|
return prefixName("redisson__idle__set", getRawName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getOptionsName() {
|
|
|
|
|
return suffixName(getRawName(), "redisson_options");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getOptionsName(String name) {
|
|
|
|
|
return suffixName(name, "redisson_options");
|
|
|
|
|
}
|
|
|
|
@ -1874,8 +1870,8 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "table.insert(result, val); "
|
|
|
|
|
+ "end;"
|
|
|
|
|
+ "return result;",
|
|
|
|
|
Arrays.asList(getRawName(), getTimeoutSetName(), getIdleSetName(),
|
|
|
|
|
getRemovedChannelName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.asList(getRawName(), timeoutSetName, idleSetName,
|
|
|
|
|
getRemovedChannelName(), lastAccessTimeSetName, optionsName),
|
|
|
|
|
args.toArray());
|
|
|
|
|
return future;
|
|
|
|
|
}
|
|
|
|
@ -1917,8 +1913,8 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "end; "
|
|
|
|
|
|
|
|
|
|
+ "return n; ",
|
|
|
|
|
Arrays.asList(getRawName(), getTimeoutSetName(), getIdleSetName(),
|
|
|
|
|
getRemovedChannelName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.asList(getRawName(), timeoutSetName, idleSetName,
|
|
|
|
|
getRemovedChannelName(), lastAccessTimeSetName, optionsName),
|
|
|
|
|
params.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2699,8 +2695,8 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
"end;"
|
|
|
|
|
+ "end;"
|
|
|
|
|
+ "end;",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getCreatedChannelName(),
|
|
|
|
|
getUpdatedChannelName(), getLastAccessTimeSetName(), getRemovedChannelName(), getOptionsName()),
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, getCreatedChannelName(),
|
|
|
|
|
getUpdatedChannelName(), lastAccessTimeSetName, getRemovedChannelName(), optionsName),
|
|
|
|
|
params.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2811,8 +2807,8 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
"end;"
|
|
|
|
|
+ "end;"
|
|
|
|
|
+ "end;",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getCreatedChannelName(),
|
|
|
|
|
getUpdatedChannelName(), getLastAccessTimeSetName(), getRemovedChannelName(), getOptionsName()),
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, getCreatedChannelName(),
|
|
|
|
|
getUpdatedChannelName(), lastAccessTimeSetName, getRemovedChannelName(), optionsName),
|
|
|
|
|
params.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2847,7 +2843,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
}
|
|
|
|
|
topicCodec = new MapCacheEventCodec(codec, osType);
|
|
|
|
|
}).thenCompose(r -> {
|
|
|
|
|
return commandExecutor.writeAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.HSET_VOID, getOptionsName(), "has-listeners", 1);
|
|
|
|
|
return commandExecutor.writeAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.HSET_VOID, optionsName, "has-listeners", 1);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2922,10 +2918,18 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Long> sizeInMemoryAsync() {
|
|
|
|
|
List<Object> keys = Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName());
|
|
|
|
|
List<Object> keys = Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName);
|
|
|
|
|
return super.sizeInMemoryAsync(keys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> copyAsync(List<Object> keys, int database, boolean replace) {
|
|
|
|
|
String newName = (String) keys.get(1);
|
|
|
|
|
List<Object> kks = Arrays.asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName,
|
|
|
|
|
newName, getTimeoutSetName(newName), getIdleSetName(newName), getLastAccessTimeSetName(newName), getOptionsName(newName));
|
|
|
|
|
return super.copyAsync(kks, database, replace);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void clear() {
|
|
|
|
|
get(clearAsync());
|
|
|
|
@ -2933,12 +2937,12 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> clearAsync() {
|
|
|
|
|
return deleteAsync(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName());
|
|
|
|
|
return deleteAsync(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> deleteAsync() {
|
|
|
|
|
return deleteAsync(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName());
|
|
|
|
|
return deleteAsync(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -2965,7 +2969,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "redis.call('pexpire', KEYS[2], ARGV[1]); "
|
|
|
|
|
+ "redis.call('pexpire', KEYS[3], ARGV[1]); "
|
|
|
|
|
+ "return redis.call('pexpire', KEYS[1], ARGV[1]); ",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
timeUnit.toMillis(timeToLive), param);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2993,7 +2997,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "redis.call('pexpireat', KEYS[2], ARGV[1]); "
|
|
|
|
|
+ "redis.call('pexpireat', KEYS[3], ARGV[1]); "
|
|
|
|
|
+ "return redis.call('pexpireat', KEYS[1], ARGV[1]); ",
|
|
|
|
|
Arrays.asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
timestamp, param);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3012,7 +3016,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
"redis.call('zrem', KEYS[3], 'redisson__expiretag'); " +
|
|
|
|
|
"redis.call('persist', KEYS[3]); " +
|
|
|
|
|
"return redis.call('persist', KEYS[1]); ",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()));
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -3053,7 +3057,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "end;" +
|
|
|
|
|
"return result;",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
System.currentTimeMillis());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3098,7 +3102,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "end;" +
|
|
|
|
|
"return result;",
|
|
|
|
|
Arrays.asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
System.currentTimeMillis(), count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3144,7 +3148,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "end;" +
|
|
|
|
|
"return result;",
|
|
|
|
|
Arrays.asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
System.currentTimeMillis(), count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3191,7 +3195,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "end;" +
|
|
|
|
|
"return result;",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
System.currentTimeMillis());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3239,7 +3243,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "end;" +
|
|
|
|
|
"return result;",
|
|
|
|
|
Arrays.<Object>asList(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName()),
|
|
|
|
|
Arrays.<Object>asList(getRawName(), timeoutSetName, idleSetName, lastAccessTimeSetName, optionsName),
|
|
|
|
|
System.currentTimeMillis());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|