当前位置:网站首页>Redis之Lua脚本
Redis之Lua脚本
2022-07-06 08:59:00 【~庞贝】
Redis之Lua脚本
1.Redis脚本介绍
Redis 脚本使用 Lua 解释器来执行脚本,Reids通过内嵌支持 Lua 环境。
2.eval
执行脚本的常用命令为 EVAL。
参数说明:
1.script: 参数是一段 Lua 5.1 脚本程序。脚本不必(也不应该)定义为一个 Lua 函数。
2.numkeys: 用于指定键名参数的个数。
3.key [key …]: 从 EVAL 的第三个参数开始算起,表示在脚本中所用到的那些 Redis 键(key),这些键名参数可以在 Lua 中通过全局变量 KEYS 数组,用 1 为基址的形式访问( KEYS[1] , KEYS[2] ,以此类推)。
4.arg [arg …]: 附加参数,在 Lua 中通过全局变量 ARGV 数组访问,访问的形式和 KEYS 变量类似( ARGV[1] 、 ARGV[2] ,诸如此类)。
EVAL script numkeys key [key ...] arg [arg ...]

3.evalsha
Evalsha 命令根据给定的 sha1 校验码,执行缓存在服务器中的脚本.
参数说明:
1.script: 参数是一段 Lua 5.1 脚本程序。脚本不必(也不应该)定义为一个 Lua 函数。
2.numkeys: 用于指定键名参数的个数。
3.key [key …]: 从 EVAL 的第三个参数开始算起,表示在脚本中所用到的那些 Redis 键(key),这些键名参数可以在 Lua 中通过全局变量 KEYS 数组,用 1 为基址的形式访问( KEYS[1] , KEYS[2] ,以此类推)。
4.arg [arg …]: 附加参数,在 Lua 中通过全局变量 ARGV 数组访问,访问的形式和 KEYS 变量类似( ARGV[1] 、 ARGV[2] ,诸如此
EVALSHA sha1 numkeys key [key ...] arg [arg ...]

4.script kill
Script kill 命令用于杀死当前正在运行的 Lua 脚本,当且仅当这个脚本没有执行过任何写操作时,这个命令才生效。
这个命令主要用于终止运行时间过长的脚本,比如一个因为 BUG 而发生无限循环的脚本。
SCRIPT KILL 执行之后,当前正在运行的脚本会被杀死,执行这个脚本的客户端会从 EVAL 命令的阻塞当中退出,并收到一个错误作为返回值。
返回值:总是返回 OK
SCRIPT KILL

5.script load
Redis Script Load 命令用于将脚本 script 添加到脚本缓存中,但并不立即执行这个脚本。
EVAL 命令也会将脚本添加到脚本缓存中,但是它会立即对输入的脚本进行求值。
如果给定的脚本已经在缓存里面了,那么不执行任何操作。
在脚本被加入到缓存之后,通过 EVALSHA 命令,可以使用脚本的 SHA1 校验和来调用这个脚本。
脚本可以在缓存中保留无限长的时间,直到执行 SCRIPT FLUSH 为止。
返回值:给定脚本的 SHA1 校验和
SCRIPT LOAD script

6.script exists
Script Exists 命令用于校验指定的脚本是否已经被保存在缓存当中。
返回值:
一个列表,包含 0 和 1 ,前者表示脚本不存在于缓存,后者表示脚本已经在缓存里面了。
列表中的元素和给定的 SHA1 校验和保持对应关系,比如列表的第三个元素的值就表示第三个 SHA1 校验和所指定的脚本在缓存中的状态。
SCRIPT EXISTS sha1 [sha1 ...]

7.script flush
Flush 命令用于清除所有 Lua 脚本缓存。
返回值:总是返回 OK
SCRIPT FLUSH

边栏推荐
- Kratos战神微服务框架(三)
- Advance Computer Network Review(1)——FatTree
- IDS cache preheating, avalanche, penetration
- Intel distiller Toolkit - Quantitative implementation 1
- Leetcode: Jianzhi offer 03 Duplicate numbers in array
- 【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
- Leetcode刷题题解2.1.1
- Heap (priority queue) topic
- 如何正确截取字符串(例:应用报错信息截取入库操作)
- Intel Distiller工具包-量化实现1
猜你喜欢
![[OC]-<UI入门>--常用控件的学习](/img/2c/d317166e90e1efb142b11d4ed9acb7.png)
[OC]-<UI入门>--常用控件的学习

Blue Bridge Cup_ Single chip microcomputer_ Measure the frequency of 555

Intel distiller Toolkit - Quantitative implementation 2

Redis之cluster集群

BMINF的後訓練量化實現

Once you change the test steps, write all the code. Why not try yaml to realize data-driven?

IDS cache preheating, avalanche, penetration
![[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)](/img/af/a44c2845c254e4f48abde013344c2b.png)
[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)

什么是MySQL?MySql的学习之路是怎样的

Mise en œuvre de la quantification post - formation du bminf
随机推荐
What is an R-value reference and what is the difference between it and an l-value?
Simclr: comparative learning in NLP
Advance Computer Network Review(1)——FatTree
Redis之主从复制
QML control type: Popup
【图的三大存储方式】只会用邻接矩阵就out了
数学建模2004B题(输电问题)
[shell script] use menu commands to build scripts for creating folders in the cluster
Compétences en mémoire des graphiques UML
Redis之连接redis服务命令
LeetCode:236. The nearest common ancestor of binary tree
Blue Bridge Cup_ Single chip microcomputer_ PWM output
自定义卷积注意力算子的CUDA实现
MySQL uninstallation and installation methods
Intel Distiller工具包-量化实现1
In depth analysis and encapsulation call of requests
What is MySQL? What is the learning path of MySQL
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
LeetCode:41. Missing first positive number
Kratos ares microservice framework (II)