2013-03-19 47 views
3

最近我一直在玩Redis,想知道如何一次完成多個鍵的觀看。 下面的東西會是原子嗎?是否有可能在Python中觀察多個Redis KEYs?

以下代碼使用redis-py;

while True:    
     try: 
      pipe.watch(key) 
      pipe.watch(another_key) 
      pipe.multi() 
      pipe.set(key, value) 
      pipe.set(another_key, another_value) 
      pipe.execute() 

      break 
     except redis.WatchError: 
      continue 

     finally: 
      pipe.reset() 

回答

5

的Redis有多個按鍵的支持,是:http://redis.io/commands/watch

雖然蟒蛇客戶端的文檔說流水線命令執行原子,我仍然會用一個WATCH調用使用多個參數:

pipe.watch(key, another_key) 
+0

大聲笑我已經通過文件至少5次左右。有趣的事情沒有注意到這些參數。 – xzvkm 2013-03-20 23:11:12