redis键过期发送消息配置

原文链接: https://my.oschina.net/u/1763091/blog/3034760


一、键空间通知配置,配置该项会消耗性能。

1、首先配置键空间通知类型,如下例子:开启key过期通知

config set notify-keyspace-events Ex 
config set notify-keyspace-events Kx

K    键空间通知,所有通知以 __keyspace@__ 为前缀,针对Key
E    键事件通知,所有通知以 __keyevent@__ 为前缀,针对event
g    DEL 、 EXPIRE 、 RENAME 等类型无关的通用命令的通知
$    字符串命令的通知
l    列表命令的通知
s    集合命令的通知
h    哈希命令的通知
z    有序集合命令的通知
x    过期事件:每当有过期键被删除时发送
e    驱逐(evict)事件:每当有键因为 maxmemory 政策而被删除时发送
A    参数 g$lshzxe 的别名,相当于是All

2、配置订阅事件
    1)、开启键过期事件

        PSUBSCRIBE __keyevent@__:OpsType (OpsType可以为expired,del,set...等操作)

    2)、针对特殊key过滤

        PSUBSCRIBE __keyspace@__:KeyPattern

转载于:https://my.oschina.net/u/1763091/blog/3034760

你可能感兴趣的:(redis键过期发送消息配置)