w3resource

Redis Scripting: SCRIPT EXISTS script [script ...]

Redis SCRIPT EXISTS Command

Redis SCRIPT EXISTS command is used to return information about the existence of the scripts in the script cache. This command accepts one or more SHA1 digests and returns a list of ones or zeros to signal if the scripts are already defined or not inside the script cache.

Here are some common uses and scenarios for the "SCRIPT EXISTS" command:

  • Check Script Availability: Verifies if one or more scripts are already cached in the Redis script cache by checking their SHA1 hashes.
  • Optimize Execution: Helps optimize script execution by determining whether a script needs to be loaded before executing it with EVALSHA.
  • Cache Management: Aids in managing the script cache by allowing users to check for the presence of specific scripts and avoid unnecessary script reloading.
  • Conditional Logic: Enables conditional logic based on the presence of scripts in the cache, ensuring that scripts are only sent and executed if not already cached.

Syntax:

SCRIPT EXISTS script [script ...]

Available since

2.6.0.

Return Value

Array reply The command returns an array of integers that correspond to the specified SHA1 digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache, and 1 is returned, otherwise, 0 is returned.

Return Value Type

Array

Example:

redis 127.0.0.1:6379> SCRIPT LOAD "return 1"
ERR Unknown or disabled command 'SCRIPT'
redis 127.0.0.1:6379> SCRIPT EXISTS ff9d4800c877a703b823dsdsfsffewfwefwefweac0578ff8db
ERR Unknown or disabled command 'SCRIPT'

Previous: EVALSHA
Next: SCRIPT FLUSH



Follow us on Facebook and Twitter for latest update.