My second multi() call requires results from the first multi(). However I want all commands from both multi() to be executed atomically. How can I do this?
This is using the node.js client.
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()
});
You should be able to use redis EVAL to do complicated work in an atomic transaction. My understanding is the EVAL command is written to the tx log so even if redis crashes the whole command will either run to completion or not be performed at all.