当前位置:网站首页>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 ares microservice framework (II)
- How to intercept the string correctly (for example, intercepting the stock in operation by applying the error information)
- Mathematical modeling 2004b question (transmission problem)
- 在QWidget上实现窗口阻塞
- Ijcai2022 collection of papers (continuously updated)
- Nacos installation and service registration
- [oc]- < getting started with UI> -- common controls uibutton
- Reids之删除策略
- BN folding and its quantification
- LeetCode:162. Looking for peak
猜你喜欢
![[OC-Foundation框架]---【集合数组】](/img/b5/5e49ab9d026c60816f90f0c47b2ad8.png)
[OC-Foundation框架]---【集合数组】

QDialog
![[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)

Redis之五大基础数据结构深入、应用场景

BMINF的後訓練量化實現

Redis之发布订阅

Redis之Bitmap
![[OC foundation framework] - string and date and time >](/img/75/e20064fd0066810135771a01f54360.png)
[OC foundation framework] - string and date and time >

Redis之连接redis服务命令

Advanced Computer Network Review(5)——COPE
随机推荐
IJCAI2022论文合集(持续更新中)
Once you change the test steps, write all the code. Why not try yaml to realize data-driven?
Redis之发布订阅
[OC-Foundation框架]--<Copy对象复制>
Notes 01
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
[Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
QML type: overlay
MySQL uninstallation and installation methods
AcWing 2456. 记事本
LeetCode:673. Number of longest increasing subsequences
【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
Redis之五大基础数据结构深入、应用场景
Selenium+pytest automated test framework practice (Part 2)
使用标签模板解决用户恶意输入的问题
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
Le modèle sentinelle de redis
多元聚类分析
Mathematical modeling 2004b question (transmission problem)
AcWing 2456. Notepad