惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AWS News Blog
AWS News Blog
T
Tenable Blog
Project Zero
Project Zero
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 热门话题
T
Threat Research - Cisco Blogs
T
Threatpost
Security Latest
Security Latest
C
Cisco Blogs
L
Lohrmann on Cybersecurity
S
Security @ Cisco Blogs
Google Online Security Blog
Google Online Security Blog
NISL@THU
NISL@THU
AI
AI
V
Vulnerabilities – Threatpost
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Last Watchdog
The Last Watchdog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Hacker News: Front Page
U
Unit 42
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MyScale Blog
MyScale Blog
O
OpenAI News
Scott Helme
Scott Helme
V2EX - 技术
V2EX - 技术
P
Proofpoint News Feed
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
H
Heimdal Security Blog
S
Schneier on Security
阮一峰的网络日志
阮一峰的网络日志
Help Net Security
Help Net Security
D
DataBreaches.Net
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
TaoSecurity Blog
TaoSecurity Blog
K
Kaspersky official blog
N
News and Events Feed by Topic
WordPress大学
WordPress大学
P
Palo Alto Networks Blog

博客园 - coffee

apache配置http跳转https centos7使用yum安装mysql5.7 sun.misc.BASE64Encoder找不到jar包的解决方法 使用命令修改git的用户名和提交的邮箱 apache,请求来源特定域名,重定向到图片域名。 使用cron+php脚本监控后台任务脚本 Shell_exec php with nohup git常用命令 Jenkins+Gitee异常解决 kafka安装和简单测试 statsvn使用小记 java.net.URLEncoder对中文的编码和解码 Apache配置WebSocket代理 php批量检查https证书有效期 504 Gateway Time-out ( Nginx + PHP ) 解决小计 VMware 扩展磁盘容量 查看mysql字符集、修改数据库、数据表、字段字符集 Docker常用命令 Docker 安装 MySQL 学习笔记
Jboot实现Redis操作事件通知
coffee · 2020-03-25 · via 博客园 - coffee

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