Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Redis script


May 16, 2021 Redis


Table of contents


Redis script

The Redis script uses the Lua interpreter to execute the script. R eids 2.6 supports Lua environments by embedding. T he common command to execute a script is EVAL.

Grammar

The basic syntax of the Eval command is as follows:

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

Instance

The following example demonstrates how the redis script works:

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 command

The following table lists common commands for redis scripts:

Serial number Commands and descriptions
1 EVAL script numkeys key [key ...] arg [arg ...]
Execute the Lua script.
2 EVALSHA sha1 numkeys key [key ...] arg [arg ...]
Execute the Lua script.
3 SCRIPT EXISTS script [script ...]
Check to see if the specified script has been saved in the cache.
4 SCRIPT FLUSH
Remove all scripts from the script cache.
5 SCRIPT KILL
Kills the Lua script that is currently running.
6 SCRIPT LOAD script
Add the script script to the script cache, but the script is not executed immediately.