Easy Tutorial
❮ Redis Server Lists Rpop ❯

Redis Scripts

Redis scripts use the Lua interpreter to execute scripts. Redis version 2.6 introduced embedded support for the Lua environment. The common command for executing scripts is EVAL.

Syntax

The basic syntax for 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 process of Redis scripting:

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 table below lists common Redis script commands:

No. Command and Description
1 EVAL script numkeys key [key ...] arg [arg ...] <br>Executes a Lua script.
2 EVALSHA sha1 numkeys key [key ...] arg [arg ...] <br>Executes a Lua script.
3 SCRIPT EXISTS script [script ...] <br>Checks whether the specified script is already in the cache.
4 SCRIPT FLUSH <br>Removes all scripts from the script cache.
5 SCRIPT KILL <br>Kills the currently running Lua script.
6 SCRIPT LOAD script <br>Adds the script to the script cache without executing it immediately.
❮ Redis Server Lists Rpop ❯