Redis command o...login
Redis command operation Chinese manual
author:php.cn  update time:2022-04-12 14:07:28

Redis script


Redis scripts use the Lua interpreter to execute scripts. Reids version 2.6 supports the Lua environment via built-in. The common command to execute scripts is EVAL.

Syntax

The basic syntax of the Eval command is as follows:

redis 127.0.0.1:6379> EVAL script numkeys key [key ...] arg [arg ...]

Example

The following example demonstrates the redis script working process:

redis 127.0.0.1:6379> EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second

1) "key1"
2) "key2"
3) "first"
4) "second"

Redis script commands

The following table lists common commands for redis scripts:

Serial numberCommand and description
1EVAL script numkeys key [key ...] arg [arg ...]
Execute Lua script.
2EVALSHA sha1 numkeys key [key ...] arg [arg ...]
Execute Lua script.
3SCRIPT EXISTS script [script ...]
Check whether the specified script has been saved in the cache.
4SCRIPT FLUSH
Remove all scripts from the script cache.
5SCRIPT KILL
Kill the currently running Lua script.
6SCRIPT LOAD script
Add script script to the script cache, but do not execute the script immediately.

php.cn