News for hackers. Stuff that matters.
Re:Redis: the AK-47 of databases by IgorPartola on Friday January 28, 2011 @10:48AM (#2152219)
Ah: http://redis.io/commands/multi. So the problem with this approach is that there are no consistent reads. If I say:

  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.
Re:Redis: the AK-47 of databases by antirez on Friday January 28, 2011 @12:11PM (#2152593)
MULTI/EXEC is completely atomic and transactional.

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.

Re:Redis: the AK-47 of databases by IgorPartola on Friday January 28, 2011 @12:40PM (#2152695)
Ah, that makes sense. I imagine allowing atomic reads without WATCH would complicate the code quite a bit.
Re:Redis: the AK-47 of databases by antirez on Friday January 28, 2011 @02:01PM (#2153040)
Indeed, not very Redis-ish :)

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.

Re:Redis: the AK-47 of databases by lukesandberg on Friday January 28, 2011 @11:03AM (#2152298)
im not exactly sure about that but i know that at least for integers there are atomic update commands and that for strings there are atomic append commands.

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

Re:Redis: the AK-47 of databases by liuliu on Friday January 28, 2011 @11:55AM (#2152531)
Redis is single-thread one-process program. Since the execution only happens when EXEC command received, such scenario cannot exist.