The Lua scripting that will be shipped with the forthcoming Redis
scripting branch (whenever that happens) will make this even easier.
- Josiah
> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/redis-db/-/HEbIeVHF1VsJ.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to
> redis-db+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/redis-db?hl=en.
>
what about using WATCH? ie:
WATCH balanceA
GET balanceA
if balanceA >= 100 --- check on the client app
MULTI
DECRBY balanceA 100
INCRBY balanceB 100
EXEC
else
UNWATCH
--
Javier
Your multi/exec solution is also good assuming low volumes of update contention.
- Josiah
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
- Josiah
> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/redis-db/-/-MYmhV_8e7IJ.
so with the lua scripting branch, you'll be able to do something like what I put in my pseudo code, and tell redis to do all commands transactionally? that would be great.
--You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/-MYmhV_8e7IJ.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
i think the real reason why Lua operations are atomic is because
they're a _single_ operation, and Redis is single threaded.
--
Javier
--
Javier
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
not sure if i get you.... do you mean that Lua commands are wrapped in
an implicit MULTI...EXEC?
what happens if, for example, i have a Lua function that:
1:- write to a Redis Hash
2:- dies of a Lua error (division by zero, call to a nil value, whatever)
3:- writes to a second Hash
obviously step 3 wouldn't be performed, but what about step 1's write
operation? would it be performed before the error? or are every
modification delayed until Lua returns and applied only if there
wasn't an error?
--
Javier
On Thu, Jun 23, 2011 at 6:44 AM, David Yu <david....@gmail.com> wrote:not sure if i get you.... do you mean that Lua commands are wrapped in
> On Thu, Jun 23, 2011 at 7:37 PM, Javier Guerra Giraldez <jav...@guerrag.com>
> wrote:
>>
>> On Wed, Jun 22, 2011 at 7:12 PM, David Yu <david....@gmail.com> wrote:
>> > With redis, you don't write until the last condition is met, which makes
>> > your lua function atomic.
>>
>> i think the real reason why Lua operations are atomic is because
>> they're a _single_ operation, and Redis is single threaded.
>
> If you compare redis to voltdb (both in-memory and both have no locks/etc),
> the latter supports full transactions where you can rollback any changes you
> made. With redis, you can't ... w/c is why you have to make sure each
> condition is met before you write.
an implicit MULTI...EXEC?
what happens if, for example, i have a Lua function that:
1:- write to a Redis Hash
2:- dies of a Lua error (division by zero, call to a nil value, whatever)
3:- writes to a second Hash
obviously step 3 wouldn't be performed, but what about step 1's write
operation?
would it be performed before the error? or are every
modification delayed until Lua returns and applied only if there
wasn't an error?
--
Javier
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
great, that was i assumed. and (IMHO) in line with the principle of
least surprise.
then:
A) Lua commands are atomic because of Redis single-threadness, not
because of check-before-commit.
B) database consistency is responsibility of the user, with or
without Lua scripts.
--
Javier
Javier
doh!
so, the correct term is synchronized? or more like 'sequential' (or
sequentialized) ?
--
Javier