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

  • 相关阅读:
    kubernetes yaml文件格式
    docker 镜像上传至私有仓库
    Docker Compose编排容器
    jenkins+gitlab+ansible+dockerfile+k8s自动发布代码
    kubernetes 命令行
    关于HDFS的读写流程
    vue中watched属性
    app中rem算法
    vue使用中的随笔
    react 表单获取多个input
  • 原文地址:https://www.cnblogs.com/june0816/p/11462912.html
Copyright © 2011-2022 走看看