Lua Scripts is really atomic?

1,062 views
Skip to first unread message

Luciano Sousa

unread,
Sep 3, 2018, 5:19:38 PM9/3/18
to Redis DB

Hi, I have a doubt about Script Lua and Transaction

 

Tha page about Transaction Topic says: Redis script is transactional by definition, so everything you can do with a Redis transaction, you can also do with a script, and usually the script will be both simpler and faster.

 

My doubt is, if my script is interrupt because server is down, whats happen when the server come back up? The data manipuled by script is rolled back?

hva...@gmail.com

unread,
Sep 3, 2018, 10:44:49 PM9/3/18
to Redis DB
There's more on the topic in the transactions page (https://redis.io/topics/transactions) than in the EVAL command page.  Specifically:

2nd bullet point on the page says, in part:
  • Either all of the commands or none are processed, so a Redis transaction is also atomic. The EXEC command triggers the execution of all the commands in the transaction, so if a client loses the connection to the server in the context of a transaction before calling the MULTI command none of the operations are performed, instead if the EXEC command is called, all the operations are performed. [two sentences deleted for clarity]  However if the Redis server crashes or is killed by the system administrator in some hard way it is possible that only a partial number of operations are registered. Redis will detect this condition at restart, and will exit with an error.
A section farther down the page is also relevant:  https://redis.io/topics/transactions#why-redis-does-not-support-roll-backs

Luciano Sousa

unread,
Sep 4, 2018, 10:00:37 AM9/4/18
to Redis DB
Thank's for reply

I guess that I not was be clear.

I was know that transaction can be "rolledback" with redis-cache-aof tool when Redis Server crashes, but I yet have doubt if the "rollback" is executed when Redis Server crashes during the execution of lua script. In fact that I need to know is if when Redis Server crashes, Redis Server can will detect if any lua script was not complete and also exit with error and if it can be recovery with redis-check-aof tool or any other tool.

Itamar Haber

unread,
Sep 4, 2018, 10:14:48 AM9/4/18
to Redis DB
Hello Luciano,

If I remember my Redis internals correctly, time kinda stops when you run a Lua script. Specifically, persistence tasks are handled by the event loop only after the script completes, so a server failure during the script will not persist the changes so made so far.

I hope this makes sense, answers your question (and is validated by at least one other person who knows Redis ;)).

Cheers,

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber
Technicalist Evangenly

Phone: +972.54.567.9692

Redis Labs


hva...@gmail.com

unread,
Sep 4, 2018, 12:12:18 PM9/4/18
to Redis DB

When people envision transactions, they have two characteristics in mind:
  1. Multiple changes made within the transaction are atomic.  I.e., the other clients do not see any of the changes until the transaction is complete, then other client see all the changes together.
  2. When a transaction fails, all changes made as part of the transaction are "rolled back".  I.e., the other clients do not see any of the transaction changes.
(there are other characteristics, but they are minor and aren't relevant to this comparison with Redis) These two characteristics, like the term "transaction" come from relational databases (RDBs).

Redis is not an RDB.  The Redis documentation is clear about how Redis "trasactions" work.  The things that Redis calls "transactions" have the atomic characteristic listed above, but they do not have the "roll back" characteristic.  This is true of the multiple commands performed within a MULTI/EXEC block, and it's true of Lua scripts, which are implemented as if they have a MULTI/EXEC block wrapped around them.  Atomic, but no rollback.
Reply all
Reply to author
Forward
0 new messages