Redis 2.6: Lua Scripting, Server-Side Scripts, and Commands

Run code inside your database cache. We explore Redis Lua scripting, transactional safety, and new commands.

VP
SHIVAM ITCS
·2 September 2012·10 min read·1 views

High-Performance Cache Abstractions

Redis has established itself as the leading in-memory key-value data store for caching and session management. However, executing multi-step operations (e.g. check a key, modify a counter, update a set) historically required multiple client round-trips or fragile transaction watches.

The launch of Redis 2.6 in late 2012 addresses this by introducing Server-Side Lua Scripting.

Server-Side Lua Scripting

Redis 2.6 embeds a Lua interpreter inside the database server.

  • Atomic Execution: Lua scripts run atomically. No other client commands can execute while a script is running, ensuring transactional safety.
  • Reduced Network Latency: Multiple operations are combined into a single script executed on-server, removing database query round-trips.
luacode
-- A simple Redis Lua script in 2012
local current = redis.call('get', KEYS[1])
if current == 'active' then
    return redis.call('incr', KEYS[2])
else
    return 0
end

Additional Features in 2.6

  • Millisecond Expirations: Allowing highly precise caching keys.
  • Improved Memory Reporting: Streamlining performance tracking.
VP
Vijay Paliwal
Founder, SHIVAM ITCS · 18+ years enterprise & AI engineering
MCA · Ex-HiveGPT USA · Ex-Social27 Seattle
Redis 2.6: Lua Scripting, Server-Side Scripts, and Commands | SHIVAM ITCS Blog | SHIVAM ITCS