成功写入命令后Redis Lua脚本出错

根据Redis文档,lua脚本以原子方式执行.我认为这也意味着scipts作为事务运行,也就是说,脚本中的所有写命令都成功或失败.

但是我注意到,即使脚本稍后返回错误,写入命令更改也会持续存在.

例如,在从redis cli运行以下命令后,键“k”的值为“1”,即使脚本本身返回有关访问全局变量的错误:

eval "redis.call(\"set\",KEYS[1],1) return x>1" 1 "k"

这是预期的吗?我错过了什么?我正在Windows上运行2.8.12版本.

最佳答案 他们所谓的“原子”实际上更接近于隔离而不是原子性:Lua脚本永远不会与其他Lua脚本或命令并发.

确切的措辞是:

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 semantics is very 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.

点赞