2012-11-01 13 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

相关问题