There is no such thing as perfect programming, but we shouldn’t be discouraged because programming is a constant pursuit of perfection.
Redis main lua script commands are:
1. eval: F_sha 2> add the script to lua_scripts_dict 3> set timeout hook 4> Execute script 5> remove timeout hook 6> return result 2. Evalsha: Script load: loads the script (the first two steps of eval). Script exists: checks whether the script exists based on SHA. 6. Script kill (shutdown nosave) : End The script process if no write operation is performed before, run the shutdown nosave command to eliminate the impact of the write operationCopy the code
The lua script execution process is shown in the following figure:
For master/slave replication in a cluster, other scripts need only be synchronized from the master server to the slave server. However, the evalsha command is special. If the master has not been synchronized to the slave server, the evalsha command may not exist. Since the f_SHA script function has not yet been synchronized to the slave server, a repl_scriptcache_dict is set to use SHA to record whether the sha function has been synchronized to all the slave servers. If so, Sha is stored in repl_Scriptcache_dict, otherwise it would not be stored, so you can use this to determine the synchronization of lua scripts, and for unsynchronized slave servers, if SHA cannot be found, eval is executed instead of Evalsha to ensure smooth execution.
For more information, follow our official account: