Redis Script Exists Command

Redis Scripts

The Redis Script Exists command is used to check whether the specified script has already been saved in the cache.

Syntax

The basic syntax of the Redis Script Exists command is as follows:

SCRIPT EXISTS sha1 [sha1 ...]

Available Versions

>= 2.6.0

Return Value

A list containing 0 and 1, where 0 indicates the script does not exist in the cache and 1 indicates the script is already in the cache.

The elements in the list correspond to the given SHA1 checksums. For example, the value of the third element in the list indicates the cache status of the script specified by the third SHA1 checksum.

Example

redis 127.0.0.1:6379> SCRIPT LOAD "return 'hello moto'"    # 载入一个脚本
"232fd51614574cf0867b83d384a5e898cfd24e5a"

redis 127.0.0.1:6379> SCRIPT EXISTS 232fd51614574cf0867b83d384a5e898cfd24e5a
1) (integer) 1

redis 127.0.0.1:6379> SCRIPT FLUSH     # 清空缓存
OK

redis 127.0.0.1:6379> SCRIPT EXISTS 232fd51614574cf0867b83d384a5e898cfd24e5a
1) (integer) 0

Redis Scripts

Other Extensions