Improvement - the scope of key event subscriptions reduced for RLiveObjectService object. Now it uses key-space channel. #5180

pull/5186/head
Nikita Koksharov 2 years ago
parent c63c81414f
commit 9176499fde

@ -73,12 +73,15 @@ public class RedissonLiveObjectService implements RLiveObjectService {
this.seachEngine = new LiveObjectSearch(commandExecutor);
if (commandExecutor.getServiceManager().getLiveObjectLatch().compareAndSet(false, true)) {
RPatternTopic topic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:expired");
String pp = "__keyspace@" + commandExecutor.getServiceManager().getConfig().getDatabase() + "__:redisson_live_object:*";
String prefix = pp.replace(":redisson_live_object:*", "");
RPatternTopic topic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, pp);
topic.addListenerAsync(String.class, (pattern, channel, msg) -> {
if (msg.contains("redisson_live_object:")) {
Class<?> entity = resolveEntity(msg);
if (msg.equals("expired")) {
String name = channel.toString().replace(prefix, "");
Class<?> entity = resolveEntity(name);
NamingScheme scheme = commandExecutor.getObjectBuilder().getNamingScheme(entity);
Object id = scheme.resolveId(msg);
Object id = scheme.resolveId(name);
deleteExpired(id, entity);
}
});

@ -1727,7 +1727,7 @@ public class RedissonLiveObjectServiceTest extends BaseTest {
.randomPort()
.randomDir()
.notifyKeyspaceEvents(
RedisRunner.KEYSPACE_EVENTS_OPTIONS.E,
RedisRunner.KEYSPACE_EVENTS_OPTIONS.K,
RedisRunner.KEYSPACE_EVENTS_OPTIONS.x)
.run();

Loading…
Cancel
Save