jonnifyechomq

The Protocol · module 03

The Lua layer

Every state change is one atomic script. The wire is not a list of commands — it is the set of scripts.

To enqueue a job is to run the @enqueue script; to claim one is to run @claim; to finish one is to run @complete. Each is the whole transition — read, decide, write — in a single server-side step no other client can interleave. That is why the scripts are the protocol: the transitions live below the language line, every key declared in KEYS[], loaded once and run by SHA. This module reads the @enqueue script in two beats, the declared-keys law, and the EVALSHA dispatch.

The wire is the set of scripts

Three transitions carry a job's life: enqueue, claim, complete. Each is one named script that declares its keys and runs atomically. Pick a verb to read its handle, the keys it declares, and the transition it performs — the catalog is the protocol.

The script catalog · pick a verb

@enqueueadmit · write · pend @claimpop · lease · active @completefence · retire one Valkey · run by SHA, every key in KEYS[]

Each verb is one declared-key script run atomically. Learn the catalog and you have read the wire.

The dives

Three dives read the Lua layer in depth, each grounded in real echo/apps/echo_mq and echo/apps/echo_wire code: the enqueue transition in two beats, the declared-keys law, and the EVALSHA dispatch that runs a script by its SHA.

built page ready to read

Pattern & implementation

Where Redis Patterns Applied teaches the move — a pattern, pushed below the language line, becomes a protocol — this module is where the move lands. The scripts are the protocol.

the pattern (Redis Patterns Applied)

An atomic multi-step update, expressed as one server-side script, becomes a protocol when the agreement is pushed below the language line. Patterns become protocol and Coordination teach it.

the implementation (echo_mq)

EchoMQ.Jobs's @enqueue / @claim / @complete each run one transition atomically, every key declared in KEYS[]; EchoMQ.Connector.eval/5 runs them by SHA.

Take the dives in order, or jump to the EVALSHA dispatch if you already know the transition. The next module — Immutability & branded ids — reads what holds the wire together.

References

Sources

Related in this course