i want to expand one redis to a Separate-read-write cluster, but my application code used lua to realize atomic op( read and then write), is it still a atomic op after expand? thank you.
Comment From: oranagra
@SmellyTrotter i don't think i understand your question. please provide more details.
some facts:
* Lua scripts are executed in redis (either Master or Replica) atomically (no other command runs while the script is running).
* The script effects are propagated to the replicas using MULTI and EXEC, e.g. a lua script that modified two keys, will be propagated as MULTI, SET x 1, set y 1, EXEC, so when executed on the replica, the effects of the script are also atomic.
Comment From: SmellyTrotter
@oranagra now i have a master and a read-only replica, and a lua script like
if(get x > 0) then decr x; return 1; end;
else return 0
just remain x non-negative
In this case, are the two operations(get and decr) still atomic?
thanks for your time
Comment From: oranagra
i assume that by get x and decr x you mean you run redis.call and execute these commands, and that this script only runs on the master.
and i assume you're using redis 5.0 or newer.
so yes, the replica will either get MULTI + DECR x + EXEC, or nothing in case the script that was executed on the master didn't do any modifications.
Comment From: oranagra
note that in order versions, the script would have been propagated as is to the replica (i.e. the replica would have run EVAL or EVALSHA), so it would still be atomic there too.