2012-11-01 16 views
0

我的第二個multi()調用需要第一個multi()的結果。不過,我希望來自這兩個multi()的所有命令都能以原子方式執行。我怎樣才能做到這一點?Redis.io multiple multi() - 它們可以是原子嗎?

這是使用node.js客戶端。

db.multi() 
    .incr('next:user:id') 
    .sadd('users:facebookid', facebookId) 
    .exec(function(err, replies) 
    { 
     var newUserId = replies[0]; 
     // if something fails in this multi(), then the previous multi() shouldn't be executed either. 
     db.multi() 
     .hmset('user:' + newUserId , 'facebookId', facebookId, 'name', userName) 
     .incr('users:count') 
     .exec() 

    }); 

回答

1

您應該能夠使用redis EVAL在原子事務中執行復雜的工作。我的理解是將EVAL命令寫入tx日誌,因此即使redis崩潰,整個命令也會運行完成或根本不會執行。

+0

感謝您的支持。儘管我認爲我的方法論首先是錯誤的,但最終我把所有'get data'命令放在第一個multi和我的所有'write data'命令中。 – user1481414

相關問題