具体来说,为一个一直连接服务器的客户端做一个假设是比较好的,这个假设就是这个连接缓存的脚本一直都在服务器缓存着的,除非有服务器管理权限的人执行 SCRIPT FLUSH命令。 The fact that the user can count on Redis not removing scripts is semantically useful in the context of pipelining.
在使用管道的情况下,用户对没有被删除的脚本进行计数是很有用的。
For instance an application with a persistent connection to Redis can be sure that if a script was sent once it is still in memory, so eva lSHA can be used against those scripts in a pipeline without the chance of an error being generated due to an unknown script (we'll see this problem in detail later).
例如,一个一直连接Redis的应用就能确保一个脚本发生一次之后就一直在reids内存中,因此eva lSHA可以防备那些在管道里面的脚本,使之没有机会产生未知脚错误(稍后将看到这个问题)。 A common pattern is to call SCRIPT LOAD to load all the scripts that will appear in a pipeline, then use eva lSHA directly inside the pipeline without any need to check for errors resulting from the script hash not being recognized.
一个普遍的做法是调用SCRIPT LOAD去加载在一个管道里出现所有的脚本,然后直接在管道里使用eva lSHA,而不用去检测脚本没有被认可产生的错误。
?
The SCRIPT command 脚本命令
Redis offers a SCRIPT command that can be used in order to control the scripting subsystem. SCRIPT currently accepts three different commands:Redis为了去控制脚本子系统提供SCRIPT命令。SCRIPT通常接收三个不同的命令:
SCRIPT FLUSH. This command is the only way to force Redis to flush the scripts cache. It is most useful in a cloud environment where the same instance can be reassigned to a different user. It is also useful for testing client libraries' implementations of the scripting feature.
SRIPUT FLUSH。这个命令时使Redis清空脚本缓存的唯一方式。在云环境中当同一个实例被重新指定给不同的用户时这个命令是最有用的。在客户端测试脚本的实现时也非常有用。
SCRIPT EXISTS sha1 sha2... shaN. Given a list of SHA1 digests as arguments this command returns an array of 1 or 0, where 1 means the specific SHA1 is recognized as a script already present in the scripting cache, while 0 means that a script with this SHA1 was never seen before (or at least never seen after the latest SCRIPT FLUSH command).
SCRIPT EXISTS sha1 sha2...shaN。命令的参数是SHA1摘要的列表,它将返回一个由0或者1组成的数组,1表示对应的脚本已经被服务器认可放入脚本缓存了,0表对应的脚本服务器一直都没有见过(或者至少在最后一次执行SCRIPT FLUSH后从来没有见过)
SCRIPT LOAD script. This command registers the specified script in the Redis script cache. The command is useful in all the contexts where we want to make sure that eva lSHA will not fail (for instance during a pipeline or MULTI/EXEC operation), without the need to actually execute the script.
SCRIPT LOAD script. 这个命令是在Redis脚本缓存中缓存指定的脚本。这个命令在我们想确保eva lSHA不管在任何环境下都不会失败时非常有用(比如在管道或者 MULTI/EXEC 操作时),并且加载时它不会去执行脚本。
SCRIPT KILL. This command is the only way to interrupt a long-running script that reaches the configured maximum execution time for scripts. The SCRIPT KILL command can only be used with scripts that did not modify the dataset during their execution (since stopping a read-only script does not violate the scripting engine's guaranteed atomicity). See the next sections for more information about long running scripts.
SCRIPT KILL.这个命令是去中断正在运行并且运行时间达到配置最大时间的脚本的唯一方式。这个命令只能使用于脚本执行不修改数据的情况(因为停止脚本不能违反脚本引擎的原子性)。下一小节将看到关于长时间运行脚本的更多信息。