当前位置:网站首页>Lua script of redis

Lua script of redis

2022-07-06 09:21:00 ~Pompeii

Redis And Lua Script

1.Redis Script Introduction

Redis Script use Lua Interpreter to execute the script ,Reids Supported by inline Lua Environmental Science .

2.eval

The common command to execute a script is EVAL.
Parameter description :
1.script: The argument is a segment Lua 5.1 Script program . Scripts don't have to ( Should not be ) Define as a Lua function .
2.numkeys: Used to specify the number of key name parameters .
3.key [key …]: from EVAL The third parameter starts to count , Represents those used in scripts Redis key (key), These key name parameters can be found in Lua Through global variables KEYS Array , use 1 Form access for the base address ( KEYS[1] , KEYS[2] , And so on ).
4.arg [arg …]: Additional parameters , stay Lua Through global variables ARGV Array access , The form of access and KEYS Variables like ( ARGV[1] 、 ARGV[2] , And so on ).

EVAL script numkeys key [key ...] arg [arg ...]

 Insert picture description here

3.evalsha

Evalsha The command is based on the given sha1 Check code , Executing scripts cached in the server .
Parameter description :
1.script: The argument is a segment Lua 5.1 Script program . Scripts don't have to ( Should not be ) Define as a Lua function .
2.numkeys: Used to specify the number of key name parameters .
3.key [key …]: from EVAL The third parameter starts to count , Represents those used in scripts Redis key (key), These key name parameters can be found in Lua Through global variables KEYS Array , use 1 Form access for the base address ( KEYS[1] , KEYS[2] , And so on ).
4.arg [arg …]: Additional parameters , stay Lua Through global variables ARGV Array access , The form of access and KEYS Variables like ( ARGV[1] 、 ARGV[2] , So

 EVALSHA sha1 numkeys key [key ...] arg [arg ...] 

 Insert picture description here

4.script kill

Script kill The command is used to kill the currently running Lua Script , If and only if the script does not perform any write operations , This order will take effect .
This command is mainly used to terminate long running scripts , Like one because BUG And the script with infinite loop .
SCRIPT KILL After performing , The currently running script will be killed , The client executing this script will run from EVAL Exit from the command block , And receive an error as the return value .
Return value : Always returns OK

SCRIPT KILL

 Insert picture description here

5.script load

Redis Script Load The command is used to put the script script Add to script cache , But the script is not executed immediately .
EVAL The command also adds the script to the script cache , But it immediately evaluates the input script .
If the given script is already in the cache , Then do nothing .
After the script is added to the cache , adopt EVALSHA command , You can use script SHA1 Checksum to invoke this script .
Scripts can stay in the cache for an infinite amount of time , Until the execution of SCRIPT FLUSH until .
Return value : Of a given script SHA1 The checksum

SCRIPT LOAD script

 Insert picture description here

6.script exists

Script Exists Command is used to verify whether the specified script has been saved in the cache .

Return value :
A list of , contain 0 and 1 , The former means that the script does not exist in the cache , The latter means that the script is already in the cache .
The elements in the list and the given SHA1 Check and keep the corresponding relationship , For example, the value of the third element in the list represents the third SHA1 The state of the script specified by the checksum in the cache .

SCRIPT EXISTS sha1 [sha1 ...]

 Insert picture description here

7.script flush

Flush The command is used to clear all Lua Script cache .
Return value : Always returns OK

 SCRIPT FLUSH

 Insert picture description here

原网站

版权声明
本文为[~Pompeii]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060859159318.html