引用: https://ask.csdn.net/questions/358802 根據這里的代碼寫出監聽事件后,事件並沒有生效
在比對了多次配置文件后,終於發現了一點蹊蹺,在配置中不能有與之相沖的配置,於是處理方法就很簡單了。
將無關監聽事件注釋,再把自己需要的取消注釋,即可讓監聽事件生效
# The "notify-keyspace-events" takes as argument a string that is composed # of zero or multiple characters. The empty string means that notifications # are disabled. # # Example: to enable list and generic events, from the point of view of the # event name, use: # # notify-keyspace-events Elg #被注釋的代碼 # # Example 2: to get the stream of the expired keys subscribing to channel # name __keyevent@0__:expired use: #
#被取消注釋的代碼 notify-keyspace-events Ex
保存配置后,重啟Redis服務即可讓過期鍵監聽事件生效。