thanks Pieter and Konstantin, good news for me :)
In many years of programming, I have only used transactions for
transferring money, for all other use cases I have engineered around
transactions because they introduce complexity/locks/etc...
Many "rollbacks" can/should be implemented in client side logic where
needed.
here is an example of a TRANSACTION transfering $100 between accounts
amount = 100
WATCH account:1:amount
WATCH account:2:amount
MULTI
val = GET account:1:amount
val = val + amount
secondval = GET account:2:amount
secondval = secondval - amount
SET account:1:amount $val
SET account:2:amount $secondval
EXEC
UNWATCH account:1:amount
UNWATCH account:2:amount
Will this work? My understanding of MULTI/EXEC is if either of the two
watched keys (account:1:amount OR account2:amount) has been modified
since the WATCH, then the entire MULTI/EXEC command-list will not even
get run ... is this correct? So this "transaction" will either succeed
or fail, but not be done halfways.
On Jun 27, 11:27 pm, Konstantin Merenkov <
kmeren...@gmail.com> wrote:
> On Mon, Jun 28, 2010 at 7:57 AM, Pieter Noordhuis <
pcnoordh...@gmail.com> wrote:
> > I'm not sure what you mean. The basic idea is this: MULTI/EXEC is often
> > called a transaction, because people find it easier to understand instead of
> > calling it a "atomically executed block of commands".
>
> No, it is called a transaction because it is said so in redis
> documentation. And it tricked helluvalot of people. I lived through
> some hot debates about it.
>
> Though it is not a big deal because usually commands fail to apply due
> to operating on a wrong type of key. Like, sadd on a hash will result
> in error.
> But it is about fixing bugs in your own software :-)
>
>
>
>
>
> > However, Redis doesn't
> > support rollbacks. Every command in the M/E block is executed serially, so
> > also errors will just be returned. The only guarantee that M/E gives is
> > atomicity of the executed commands (all the ACID properties hold, by the
> > way).
> > I hope this clarifies things a bit.
> > Cheers,
> > Pieter
>