Redis – Scripting

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

Redis scripting is used to evaluate scripts using the Lua interpreter. It is built into Redis starting from version 2.6.0. The command used for scripting is EVAL command.

Syntax

Following is the basic syntax of EVAL command.

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

Example

Following example explains how Redis scripting 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 Scripting Commands

Following table lists some basic commands related to Redis Scripting.

Sr.NoCommand & Description
1EVAL script numkeys keyhttps://adglob.in/blog/redis-scripting-eval-command/
Executes a Lua script.
2EVALSHA sha1 numkeyshttps://adglob.in/blog/redis-scripting-evalsha-command/
Executes a Lua script.
3SCRIPT EXISTS scripthttps://adglob.in/blog/redis-scripting-script-exists-command/
Checks the existence of scripts in the script cache.
4SCRIPT FLUSHhttps://adglob.in/blog/redis-scripting-script-flush-command/
Removes all the scripts from the script cache.
5SCRIPT KILLhttps://adglob.in/blog/redis-scripting-script-kill-command/
Kills the script currently in execution.
6SCRIPT LOAD scripthttps://adglob.in/blog/redis-scripting-script-load-command/
Loads the specified Lua script into the script cache.

Leave a Reply