Lua Scripting
Learn how to execute server-side programs in Redis using Lua scripts.
We'll cover the following...
Redis provides the ability to execute server-side programs. This is similar to the ability to execute stored procedures in relational databases that are written using SQL (Structured Query Language). However, in Redis, the scripts are executed by an embedded engine, which currently only supports the Lua interpreter. Lua is a scripting language that supports multiple programming paradigms, including procedural, functional, object-oriented, and so on. As part of a Lua script, we can write logic that uses Redis commands to read and write data.
Benefits of Lua scripting with Redis
Some of the key benefits include the following:
Efficiency: As the name suggests, server-side programming lets us execute logic closer to the data, and the same applies to Lua scripts as well. By executing the logic in a Redis server, we reduce the overall latency and save network bandwidth.
Atomicity: A Lua script is always executed atomically in Redis because the entire server is blocked during the duration of script execution. Although this is a powerful feature, it also means that we need to careful about the correctness and execution time of our Lua scripts.
Flexibility: Because Lua is a full-fledged programming language in itself, we can implement server-side features by combining Redis commands. This allows us to build capabilities specific to our unique requirements that ...