首页 > 其他 > 详细

redis-lua-script

时间:2020-12-27 19:27:54      阅读:28      评论:0      收藏:0      [点我收藏+]

https://redis.io/commands/eval


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.

However this also means that executing slow scripts is not a good idea. It is not hard to create fast scripts, as the script overhead is very low, but if you are going to use slow scripts you should be aware that while the script is running no other client can execute commands.

 

https://redis.io/topics/transactions

Redis scripting and transactions

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.

This duplication is due to the fact that scripting was introduced in Redis 2.6 while transactions already existed long before. However we are unlikely to remove the support for transactions in the short-term because it seems semantically opportune that even without resorting to Redis scripting it is still possible to avoid race conditions, especially since the implementation complexity of Redis transactions is minimal.

However it is not impossible that in a non immediate future we‘ll see that the whole user base is just using scripts. If this happens we may deprecate and finally remove transactions.

根据官方解释

在redis执行lua脚本时其语义本身就等价于redis 事务,因此其通过在当前lua脚本执行完成之前会阻塞(同一台机器)其他任何命令的执行; 因此对于使用的lua脚本需要是一个执行速度快的;

 

关于cluster模式下脚本的执行

https://stackoverflow.com/questions/38234507/redis-cluster-update-keys-in-different-node-with-lua-script

 

因此在redis cluster 模式下如果只是操作一个key或批量操作的key能保证都在同一个节点上,其就可以实现原子操作的特性;

 

redis-lua-script

原文:https://www.cnblogs.com/xingguoblog/p/14198151.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!