English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Scripts

Redis scripts use the Lua interpreter to execute scripts. Redis 2.6 Version supports Lua environment through embedding. The commonly used 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  ...]

Online Examples

The following examples demonstrate the working process of redis scripts:

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 the commonly used redis script commands:

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 if 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 the script script to the script cache but do not execute this script immediately.