本文介绍了Redis 密钥空间通知到期未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看此页面:https://redis.io/topics/notifications

我的配置文件中设置了以下行:

I have the following line set in my config file:

notify-keyspace-events "Kx"

当我执行此操作(然后运行最终使某些密钥过期的应用程序)时,我看不到任何事件:

When I do this (and then run my application that eventually expires some keys), I see no events:

redis-cli --csv psubscribe '__keyspace*__:*expire*'

但是,当我将配置设置为:

However, when I set my config to this:

notify-keyspace-events "Kg"

然后运行相同的应用程序和 redis-cli 命令,我确实看到了事件:

And then run the same app and redis-cli command, I do see events:

"pmessage","__keyspace*__:*expire*","__keyspace@0__:spring:session:wca:sessions:expires:9d73fefc-459d-4bf4-83ef-b8fcbf06b997","expire"
"pmessage","__keyspace*__:*expire*","__keyspace@0__:spring:session:wca:sessions:expires:9d73fefc-459d-4bf4-83ef-b8fcbf06b997","expire"
"pmessage","__keyspace*__:*expire*","__keyspace@0__:spring:session:idp:sessions:expires:52dbe449-4616-41ef-bfa6-1d7a16a89f8a","expire"
"pmessage","__keyspace*__:*expire*","__keyspace@0__:spring:session:idp:sessions:expires:52dbe449-4616-41ef-bfa6-1d7a16a89f8a","expire"
"pmessage","__keyspace*__:*expire*","__keyspace@0__:spring:session:idp:sessions:expires:52dbe449-4616-41ef-bfa6-1d7a16a89f8a","expire"
"pmessage","__keyspace*__:*expire*","__keyspace@0__:spring:session:idp:sessions:expires:52dbe449-4616-41ef-bfa6-1d7a16a89f8a","expire"

我知道当 TTL 已过时,到期不一定会发生.但我不确定这能解释我所看到的——我的 redis-cli 只查找过期"事件,并且在我通知通用命令时(并且仅当)它始终会看到它们.这对我的应用来说太健谈了;我只想看看过期.

I understand that the expirations don't necessarily happen right when the TTL has elapsed. But I'm not sure that explains what I'm seeing -- my redis-cli is looking only for "expire" events, and it consistently sees them when (and only when) I notify generic commands. That's too chatty for my app; I just want to see expires.

感谢任何帮助.谢谢!

推荐答案

您订阅了错误的频道.

有两种通知:

  • 键空间通知:通道为__keyspace@__:
  • 按键事件通知:通道为__keyevent@__:
  • Key-space notification: the channel is __keyspace@<db>__:<key>
  • Key-event notification: the channel is __keyevent@<db>__:<event>

如果您想获得所有过期密钥通知,您有两种选择:

If you want to get all expired key notification, you have two choices:

  1. 启用键空间通知:config set notify-keyspace-events Kx

订阅频道:psubscribe __keyspace@*__:*

使用按键事件通知

  1. 启用按键事件通知:config set notify-keyspace-events Ex

订阅频道:psubscribe __keyevent@*__:expired

这篇关于Redis 密钥空间通知到期未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 08:11
查看更多