标签:this bst 效果 ann channels star end sage col
redis.conf
notify-keyspace-events Ex
KeyExpiredListener.java
public class KeyExpiredListener extends JedisPubSub { public KeyExpiredListener() { } @Override public void onMessage(String channel, String message) { //收到消息会调用 System.out.println(String.format("receive redis published message, channel %s, message %s", channel, message)); } @Override public void onSubscribe(String channel, int subscribedChannels) { //订阅了频道会调用 System.out.println(String.format("subscribe redis channel success, channel %s, subscribedChannels %d", channel, subscribedChannels)); } @Override public void onUnsubscribe(String channel, int subscribedChannels) { //取消订阅 会调用 System.out.println(String.format("unsubscribe redis channel, channel %s, subscribedChannels %d", channel, subscribedChannels)); } }
AppListener.java
public abstract class AppListener extends JbootAppListenerBase { @Override public void onInterceptorConfig(Interceptors interceptors) { super.onInterceptorConfig(interceptors); interceptors.add(new SessionInViewInterceptor()); } @Override public void onEngineConfig(Engine me) { } @Override public void onStart() { Aop.inject(this); Jboot.getRedis().subscribe(new KeyExpiredListener(), "__keyevent@0__:expired"); } }
测试代码
Cache.set("test-101", "101", 30); Cache.set("test-201", "201", 60); Cache.set("test-301", "301", 90);
效果
receive redis published message, channel __keyevent@0__:expired, message xxxx:S:test-101
receive redis published message, channel __keyevent@0__:expired, message xxxx:S:test-201
receive redis published message, channel __keyevent@0__:expired, message xxxx:S:test-301
标签:this bst 效果 ann channels star end sage col
原文地址:https://www.cnblogs.com/coffee_cn/p/12565112.html