0

我的第二个 multi() 调用需要第一个 multi() 的结果。但是,我希望 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()

    });
4

1 回答 1

1

您应该能够使用 redis EVAL在原子事务中完成复杂的工作。我的理解是 EVAL 命令被写入 tx 日志,所以即使 redis 崩溃,整个命令要么运行完成,要么根本不执行。

于 2012-11-01T22:32:34.450 回答