扣库存疑问

来源:4-4 Redis解决超卖问题

qq_雨声_2

2020-12-13

increment是分两步执行的。lua脚本也是两步执行操作redis命令的,只要在一个线程内执行为啥就是原子性的呢?难道用lua脚本就能保证原子性?

写回答

1回答

InCowboy

2020-12-13

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解释器来执行所有命令,同时,Redis会以一种原子性的方式来执行脚本:当lua脚本在执行的时候,不会有其他脚本和命令同时执行,所以Lua脚本的执行是原子性的。

3
0

高级Redis进阶课 解决Redis实际问题+掌握Redis6.x特性

以项目整合Redis各种场景,从此轻松应对各类Redis难题

934 学习 · 353 问题

查看课程