|
|
|
@ -63,7 +63,7 @@ public abstract class LocalCacheListener {
|
|
|
|
|
private byte[] instanceId;
|
|
|
|
|
private Codec codec;
|
|
|
|
|
private LocalCachedMapOptions<?, ?> options;
|
|
|
|
|
private final String pattern;
|
|
|
|
|
private final String keyeventPattern;
|
|
|
|
|
|
|
|
|
|
private long cacheUpdateLogTime;
|
|
|
|
|
private volatile long lastInvalidate;
|
|
|
|
@ -89,7 +89,7 @@ public abstract class LocalCacheListener {
|
|
|
|
|
this.options = options;
|
|
|
|
|
this.cacheUpdateLogTime = cacheUpdateLogTime;
|
|
|
|
|
this.isSharded = isSharded;
|
|
|
|
|
this.pattern = "__keyspace@" + commandExecutor.getServiceManager().getConfig().getDatabase() + "__:" + name;
|
|
|
|
|
this.keyeventPattern = "__keyspace@" + commandExecutor.getServiceManager().getConfig().getDatabase() + "__:" + name;
|
|
|
|
|
|
|
|
|
|
instanceId = commandExecutor.getServiceManager().generateIdArray();
|
|
|
|
|
}
|
|
|
|
@ -150,12 +150,21 @@ public abstract class LocalCacheListener {
|
|
|
|
|
invalidationTopic = RedissonTopic.createRaw(LocalCachedMessageCodec.INSTANCE, commandExecutor, getInvalidationTopicName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RPatternTopic topic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, pattern);
|
|
|
|
|
expireListenerId = topic.addListener(String.class, (pattern, channel, msg) -> {
|
|
|
|
|
if (msg.equals("expired")) {
|
|
|
|
|
cache.clear();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (options.isUseKeyEventsPattern()) {
|
|
|
|
|
RPatternTopic topic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:expired");
|
|
|
|
|
expireListenerId = topic.addListener(String.class, (pattern, channel, msg) -> {
|
|
|
|
|
if (msg.equals(name)) {
|
|
|
|
|
cache.clear();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
RTopic topic = new RedissonTopic(StringCodec.INSTANCE, commandExecutor, keyeventPattern);
|
|
|
|
|
expireListenerId = topic.addListener(String.class, (channel, msg) -> {
|
|
|
|
|
if (msg.equals("expired")) {
|
|
|
|
|
cache.clear();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.getReconnectionStrategy() != ReconnectionStrategy.NONE) {
|
|
|
|
|
reconnectionListenerId = invalidationTopic.addListener(new BaseStatusListener() {
|
|
|
|
@ -340,8 +349,13 @@ public abstract class LocalCacheListener {
|
|
|
|
|
}
|
|
|
|
|
invalidationTopic.removeListenerAsync(ids.toArray(new Integer[0]));
|
|
|
|
|
|
|
|
|
|
RPatternTopic topic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, pattern);
|
|
|
|
|
topic.removeListenerAsync(expireListenerId);
|
|
|
|
|
if (options.isUseKeyEventsPattern()) {
|
|
|
|
|
RPatternTopic topic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:expired");
|
|
|
|
|
topic.removeListenerAsync(expireListenerId);
|
|
|
|
|
} else {
|
|
|
|
|
RTopic topic = new RedissonTopic(StringCodec.INSTANCE, commandExecutor, keyeventPattern);
|
|
|
|
|
topic.removeListenerAsync(expireListenerId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getUpdatesLogName() {
|
|
|
|
|