引用: 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服務即可讓過期鍵監聽事件生效。