The Protocol · module 01
The owned keyspace
One module builds every key, to one braced grammar. The braces are the cluster hashtag.
The keyspace is the part of the protocol that says where. Every key EchoMQ writes
is composed by EchoMQ.Keyspace to one shape — emq:{q}:<type>.
The grammar is total (no key escapes the builder), the braces are the cluster hashtag
that pins one queue to one slot, and the reserved base {emq}: holds the cross-queue
version fence — first-byte-disjoint from any queue. Three dives read it in depth: the grammar, the slot the brace
computes, and the reserve.
The keyspace in three parts
The keyspace is three things, and the three dives of this module are each one of them. Pick a part to read what
it is and the real EchoMQ.Keyspace function that carries it — then take the dive.
The keyspace · pick a part
Three parts, one builder: the grammar says where a key lives, the hashtag says which slot it lands on, and the reserve says where the wire's own state goes — beside every queue, owned by none.
The dives
Three dives, each grounded in the real echo/apps/echo_mq keyspace module — the grammar
builder, the client-side slot, and the reserved base.
The braced grammar
emq:{q}:<type> from queue_key/2; the job row emq:{q}:job:<id> from job_key/2 and a validated branded id.
The hashtag & the slot
The {q} brace pins one queue to one slot; slot/1 = CRC16-XMODEM % 16384, with the vector slot("123456789")==12739.
The reserve
{emq}: is the core's reserved, first-byte-disjoint space; version_key/0 → {emq}:version; why emq can't be a queue.
Pattern → implementation
The keyspace is one applied pattern made total. Hash-tag co-location is the move; the braced grammar is the wire that fixes it as the only way a key is built.
Hash-tag co-location: wrap the shared part of a key in {...} so every member of a
logical group routes to one cluster slot, where one atomic operation can touch them together.
Redis Patterns Applied R2.05 teaches the move.
EchoMQ.Keyspace.queue_key/2 makes the brace the protocol —
emq:{q}:<type> pins every key of one queue to one slot, so the Lua layer's
declared-key scripts are always single-slot. The convention is total, not a style guide.
The pattern is the door; the keyspace is the wire. A naming convention becomes a protocol when one module builds every key to it — and the brace makes it cluster-correct by construction.
References
Sources
- Valkey — Documentation — the store every key is written to; the substrate of record.
- Redis — Keyspace & cluster hash tags — cluster key routing by the hashtag inside
{...}, the mechanism the braces use. - DragonflyDB — Server flags —
--lock_on_hashtags: the thread-per-shard placement the per-queue hashtag is built for. - llmstxt.org — The llms.txt convention — the machine-readable map format the course follows.
Related in this course
- The Protocol — the chapter this module belongs to.
- The braced grammar — dive 1: the grammar one module builds.
- The hashtag & the slot — dive 2: the slot the brace computes.
- The reserve — dive 3: the cross-queue reserve.
- redis-patterns R2.05 · Hash-tag co-location — the near side of the door.