在 Redis 配置文件中,可以通过设置 notify-keyspace-events
参数来启用键空间通知功能。以下是启用不同类型键空间通知的不同参数配置:
- 启用所有键空间通知:
notify-keyspace-events K$g$xE
- 启用键空间事件通知:
notify-keyspace-events K$
- 启用键空间命令通知:
notify-keyspace-events g$
- 启用键空间过期事件通知(keyspace "expired" ):
notify-keyspace-events Ex
- 启用键空间驱逐事件通知(keyspace "evicted"):
notify-keyspace-events Ev
- 启用键空间过期和驱逐事件通知:
notify-keyspace-events ExE
以上参数中的每个字符都代表一个选项。使用 $
符号表示启用所有选项,K
表示键空间事件,g
表示键空间命令,x
表示过期事件和E
表示驱逐事件。
设置完成后,重新启动 Redis 服务器,配置的键空间通知功能将会生效。可以通过 CONFIG GET notify-keyspace-events
命令来验证是否成功启用了键空间通知功能。