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); this.seachEngine = new LiveObjectSearch(commandExecutor);
if (commandExecutor.getServiceManager().getLiveObjectLatch().compareAndSet(false, true)) { 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) -> { topic.addListenerAsync(String.class, (pattern, channel, msg) -> {
if (msg.contains("redisson_live_object:")) { if (msg.equals("expired")) {
Class<?> entity = resolveEntity(msg); String name = channel.toString().replace(prefix, "");
Class<?> entity = resolveEntity(name);
NamingScheme scheme = commandExecutor.getObjectBuilder().getNamingScheme(entity); NamingScheme scheme = commandExecutor.getObjectBuilder().getNamingScheme(entity);
Object id = scheme.resolveId(msg); Object id = scheme.resolveId(name);
deleteExpired(id, entity); deleteExpired(id, entity);
} }
}); });

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

Loading…
Cancel
Save