SteelReed

Search

Search posts, questions…

Caching & RedisQuestion 12 / 24

Middle

How do pipelining, MULTI/EXEC and Lua scripts differ in Redis?

Short answer

A pipeline only cuts network round trips and is not atomic. MULTI/EXEC runs a block of commands without interleaving but has no rollback. A Lua script runs atomically on the server and can branch on what it reads.

only fewer round tripsa block, no interleavingread, then decide writeneeds a conditionWhat do you need?PipelineMULTI/EXECLua scriptWATCH, retry on change

3 points to say:

  1. A pipeline sends many commands at once and is not atomic; MULTI/EXEC can't read results midway, and a failed command is not rolled back.
  2. WATCH is an optimistic lock: under heavy contention it retries constantly, so Lua is usually better.
  3. Lua handles "read, then decide to write"; keep scripts short because they block the whole instance; on Cluster all keys must share one slot.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.