【发布时间】:2021-04-28 18:22:55
【问题描述】:
所以我尝试在 redis 上设置一些值时实现基本侦听器,但是当我设置一些值时,什么都没有发生,只有过期事件被调用。
订阅者
public class Subscriber {
private static JedisPool pool;
public static void main(String[] args) {
JedisPool pool = new JedisPool("localhost");
Jedis jedis = pool.getResource();
jedis.psubscribe(new SubListener(), "*");
}
}
子监听器
public class SubListener extends JedisPubSub {
@Override
public void onPSubscribe(String pattern, int subscribedChannels) {
System.out.println("onPSubscribe "
+ pattern + " " + subscribedChannels);
}
@Override
public void onPMessage(String pattern, String channel, String message) {
System.out
.println("onPMessage pattern "
+ pattern + " " + channel + " " + message);
}
}
编辑:我发现我将配置中的 notify-keyspace-events 设置为 Ex。现在我将其设置为 KEA 以调用每个事件,但我应该使用什么来仅在集合上调用事件
【问题讨论】: