MULTI
get foo # Returns 'abc'
set foo 'abcd' # (as in application code said foo += 'd')
EXEC
while another process sets foo to 'xyz' between my get and set, I just overwrote that value. No serializable transactions.You can perform just writes inside the block. If you want atomicity with reads in the middle, you need to use WATCH/MULTI/EXEC that uses an optimistic locking algorithm.
With WATCH is very easy. WATCH this keys. Perform your reads. Prepare to write in a transaction. If at least one key was modified in the meantime the transaction will fail.
so for this you would really just want to do: APPEND foo d
or for more complex situations you could do use WATCH instead of MULTI so that you can get the intermediate results. so for your example:
WATCH foo GET foo ->value //calculate new_value MULTI SET foo new_value EXEC
now if at any other operation (not part of this connection) modifies foo then the transaction will be aborted.
GET foo -> value //application logic to update value GETSET foo new_value ->prev
then prev will contain the value of foo at the time it was set, so you can then use application logic to roll back or redo the transaction
# Save the DB on disk:
#
# save <seconds> <changes>
#
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# In the example below the behaviour will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changedNow I clearly state in the doc that transactions are reflected also in the append only file, so there is no chance of partial reply.
Transactions are also applied to the master -> slave link, so also slaves will either have the full transaction or nothing.
Thanks to @garybernhardt on twitter for noticing this problem.
EDIT: looks like there is rollback support: http://redis.io/commands/discard
Also this part of the config:
is not at all obvious. Maybe it's better documented in the sample config.