Concepts · Concept

Lua Script

Lua is a lightweight general-purpose scripting language (used in game engines, embedded systems, etc.) — nothing Redis-specific about the language itself. Redis happens to embed a Lua interpreter inside the Redis server process, and exposes a command (EVAL) that lets you send a small Lua script to Redis, which Redis then runs internally, on the server, as a single unit of work.

Why this matters for atomicity: normally, when your application talks to Redis, each command (HSET, HGET, etc.) is a separate network round-trip: your app sends a command, Redis executes it, sends back a response, then your app decides what to send next. Between any two of those round-trips, another client’s request could sneak in and run on the same key — that’s your race condition.

redis.call(‘HSET’, KEYS[1], ARGV[1], ARGV[2])

return redis.call(‘HGET’, KEYS[1], ARGV[3])

Eg: used in swipe tinder