zoukankan      html  css  js  c++  java
  • Redis过期通知

    一、键空间通知Keyspace Notifications

     1. redis 2.8.0版本之后才支持

    2. 基于pub-sub

    3. 消息类型:keysapce/keyevent

    二、场景

    1. redis缓存一般要设置过期时间,否则会越来越多,但是如果缓存还有用,可以使用过期提醒来重新加载缓存

    2. 过期时需要做一些逻辑处理

    三、redis配置文件

    修改redis.conf,设置notify-keyspace-events Ex,默认为notify-keyspace-events "" ,修改后重启redis

    四、监听命令

    psubscribe __keyevent@0__:expired  //监听第0个数据库

    psubscribe __keyevent@*__:expired  //监听所有数据库

    五、关键代码

    1. 写一个类继承JedisPubSub

    class RedisMsgPubSubListener extends JedisPubSub

    2. 客户端监听

    RedisMsgPubSubListener listener = new RedisMsgPubSubListener();  
    jedis.subscribe(listener, "__keyevent@0__:expired"); //subscribe是阻塞方法

    参考:

    https://blog.csdn.net/weixin_41497481/article/details/85322794

    https://blog.csdn.net/zhu_tianwei/article/details/80169900

    https://www.cnblogs.com/ruiati/p/6655949.html

  • 相关阅读:
    液晶电子看板
    车间电子看板厂家
    车间电子看板系统
    Andon系统有哪些类型?
    Andon系统最完整的介绍
    Andon系统一般架构
    生产看板管理系统
    车间看板系统
    生产管理看板介绍
    黑马Java2020在线就业班2.1-全新升级
  • 原文地址:https://www.cnblogs.com/june0816/p/11462912.html
Copyright © 2011-2022 走看看