redis执行lua脚本原子性
redis官方解释
Atomicity of scripts
Redis uses the same Lua interpreter to run all the commands. Also Redis guarantees that a script is executed in an atomic way: no other script or Redis command will be executed while a script is being executed. This semantic is similar to the one of MULTI / EXEC. From the point of view of all the other clients the effects of a script are either still not visible or already completed.
解释:Redis采用相同的Lua解释器去运行所有命令,我们可以保证,脚本的执行是原子性的。作用就类似于加了MULTI/EXEC。
注意:脚本的执行 是原子性的。
怎么解释这个:
redis使用单个lua解释器去运行所有脚本,并且保证脚本会以原子性的方式去执行,意味着当某个脚本在运行时,不会有其它脚本或者redis命令被执行!所以,如果当前脚本运行很慢,服务器可能会因为正忙而无法执行命令
redis本身是不支持事务回滚的,那也就是说如果 在执行lua脚本过程中,有一部分命令成功了,有一部分失败了,也不会出现回滚的操作。