Skip to content

refactor: reduce command wiring boilerplate#344

Merged
kacy merged 3 commits intomainfrom
reduce-exec-boilerplate
Feb 28, 2026
Merged

refactor: reduce command wiring boilerplate#344
kacy merged 3 commits intomainfrom
reduce-exec-boilerplate

Conversation

@kacy
Copy link
Owner

@kacy kacy commented Feb 28, 2026

summary

three targeted refactors that eliminate mechanical repetition in the command wiring layer without changing architecture or behavior:

  1. route_to_shard() + response mappers — a generic helper that handles send + common error mapping (WrongType, OutOfMemory, channel errors), plus ~12 standard response mapper functions (resp_integer, resp_len, resp_ok, etc.). rewrites ~70 single-key exec handlers from 10-20 lines to 3-5 lines each. complex multi-shard handlers (mget, mset, scan, blocking ops) are unchanged.

  2. shard_request! macro — generates both the ShardRequest enum and its is_write() method from read/write variant groupings. adding a new command forces you to declare read vs write upfront — the compiler enforces it. also fixes a latent bug where SetRange was missing from is_write().

  3. cmd! macro for command table — replaces 153 verbose CommandEntry structs (7 lines each) with one-line cmd!() invocations, making the table scannable at a glance.

net result: ~1,800 lines removed across 9 files. adding a new single-key command handler goes from 10-20 lines to 3-5 lines.

what was tested

  • cargo build — full workspace compiles clean
  • cargo test -p emberkv-core -p ember-server -p ember-protocol — all 740+ tests pass
  • cargo clippy — no warnings
  • cargo fmt — formatted

kacy added 3 commits February 28, 2026 10:13
introduce a generic route_to_shard() helper that handles the repetitive
send-to-shard → match WrongType/OOM/Err/channel-error boilerplate that
every single-key command handler duplicated. paired with ~12 response
mapper functions (resp_string_value, resp_integer, resp_len, etc.) that
cover the common ShardResponse → Frame conversions.

rewrites ~70 handlers across strings.rs, hashes.rs, sets.rs,
sorted_sets.rs, lists.rs, and keyspace.rs from 8-15 lines to 3-5 lines
each. complex multi-shard handlers (mget, mset, scan, smove, sintercard,
bitop, lmpop, zmpop, etc.) are left unchanged.

net reduction: ~310 lines. adding a new single-key command handler now
takes 3 lines instead of 10-15.
…macro

the macro generates both the enum and its is_write() method from
read/write variant groupings. adding a new command forces you to
place it in the correct group — the compiler enforces it.

also fixes a bug where SetRange was missing from is_write(),
meaning SETRANGE mutations would not be rejected when the AOF
disk was full.
replaces 153 verbose CommandEntry structs (7 lines each) with
one-line cmd!() invocations. the table is now scannable at a
glance and each new command is a single line to add.
@kacy kacy merged commit 760ceb5 into main Feb 28, 2026
8 checks passed
@kacy kacy deleted the reduce-exec-boilerplate branch February 28, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant