2016-11-18 68 views
0

我正在嘗試開發基於Python和Redis的通知系統。我一直在檢查蟒蛇redismodule,我看到一個小圖案訂閱例如:訂閱模式Redis與Python

p.psubscribe('my-*', ...) 

Theorically,就是那樣,所以我嘗試類似的東西

import redis 
import time 

r =redis.StrictRedis(host = 'localhost', port=6379, db=0) 
p = r.pubsub() 
p.psubscribe('*') 

for msg in p.listen(): 
    print time.time(), msg 
    time.sleep(0.001) 

我想訂閱每個鍵以最簡單的例子。但是,我只在第一次得到這個消息,而當我改變密鑰的值時,我什麼都沒有。

1479469808.51 {'pattern': None, 'type': 'psubscribe', 'channel': '*', 'data': 1L} 

我可以看到pattern是沒有的,所以我明白,我不是真的訂閱。我如何處理它?謝謝。

回答

0

有一個非常簡單的錯誤。代碼運行良好,但我必須在Redis中執行以下命令:

config set notify-keyspace-events KEA