Skip to content

refactor: split execute.rs into exec/ sub-modules + move COMMAND_TABLE to ember-protocol#340

Merged
kacy merged 3 commits intomainfrom
refactor/execute-split
Feb 27, 2026
Merged

refactor: split execute.rs into exec/ sub-modules + move COMMAND_TABLE to ember-protocol#340
kacy merged 3 commits intomainfrom
refactor/execute-split

Conversation

@kacy
Copy link
Owner

@kacy kacy commented Feb 27, 2026

summary

execute.rs was 5000+ lines — a single match expression covering every command in the server. this makes reviews hard and navigation tedious.

this PR splits it into a proper module tree and moves command metadata to where it belongs.

what changed:

  • execute.rs is now a ~580-line thin router that constructs an ExecCtx and dispatches each Command variant to its owning sub-module
  • new exec/ directory with 13 focused files: strings, keyspace, server, lists, sorted_sets, hashes, sets, cluster, pubsub, acl, vector, protobuf, and a shared mod.rs
  • ExecCtx<'a> bundles engine + ctx + pubsub + slow_log + client_id — zero-cost, just cleaner ergonomics than 5 separate parameters in every helper
  • COMMAND_TABLE + handle_command_cmd moved to ember-protocol/src/command/table.rs — all command-describing data (enum variants, attribute methods, wire-protocol metadata) now lives in one crate

no behavior changes. this is a pure restructuring — every match arm body is identical to before, just filed in the right drawer.

what was tested

  • cargo check -p ember-server and cargo check -p ember-protocol both pass clean
  • cargo fmt applied
  • COMMAND COUNT and COMMAND INFO GET return identical values to pre-refactor
  • PING, GET, SET, ZADD, HSET all behave identically

design considerations

ExecCtx visibility is pub(in crate::connection) — accessible to all exec sub-modules and execute.rs, invisible outside the connection module. sub-module functions are pub(in crate::connection) so execute.rs can call exec::strings::get(key, &cx) directly without additional re-exports.

the #[cfg(feature = "vector")] and #[cfg(feature = "protobuf")] gates are preserved exactly as before, now scoped to their own files.

kacy added 3 commits February 27, 2026 13:50
adds the exec/ sub-directory under connection/ with mod.rs containing:
- ExecCtx<'a> struct bundling engine, ctx, pubsub, slow_log, client_id
- notify_write() helper for keyspace event emission
- set_expire_to_duration() for converting SetExpire → Duration
- multi_key_bool() fan-out helper for multi-key boolean commands
- wrongtype_error(), oom_error(), resolve_collection_scan() shared helpers

sub-module declarations are in place (pub(super) mod) but files are empty;
this commit establishes the structure before filling in the handlers.
execute.rs was a 5020-line file handling all command dispatch. this
commit distributes handlers into focused sub-modules and rewrites
execute.rs as a thin router (~580 lines):

- strings.rs    — GET/SET/INCR/DECR/APPEND/STRLEN/GETRANGE/SETRANGE
                  GETBIT/SETBIT/BITCOUNT/BITPOS/BITOP/GETDEL/GETEX
                  GETSET/MGET/MSET/MSETNX
- keyspace.rs   — DEL/UNLINK/EXISTS/TOUCH/EXPIRE/TTL/PERSIST/KEYS
                  SCAN/RENAME/COPY/RANDOMKEY/SORT/TYPE/OBJECT/MEMORY
- server.rs     — DBSIZE/INFO/CONFIG/BGSAVE/BGREWRITEAOF/TIME/ROLE
                  FLUSHDB/FLUSHALL/SLOWLOG/WAIT and render_info helper
- lists.rs      — LPUSH/RPUSH/LPOP/RPOP/LRANGE/LLEN/LINDEX/LSET
                  LTRIM/LINSERT/LREM/LPOS/LMOVE/LMPOP/blocking stubs
- sorted_sets.rs — ZADD/ZREM/ZSCORE/ZRANK/ZRANGE/ZCOUNT/ZINCRBY
                  ZRANGEBYSCORE/ZPOPMIN/ZMPOP/ZDIFF/ZSTORE/ZRANDMEMBER
- hashes.rs     — HSET/HGET/HGETALL/HDEL/HEXISTS/HLEN/HINCRBY
                  HINCRBYFLOAT/HKEYS/HVALS/HMGET/HRANDFIELD/HSCAN
- sets.rs       — SADD/SREM/SMEMBERS/SISMEMBER/SCARD/SUNION/SINTER
                  SDIFF/SSTORE/SRANDMEMBER/SPOP/SMISMEMBER/SMOVE/SINTERCARD
- cluster.rs    — all CLUSTER_* commands, MIGRATE, RESTORE
- pubsub.rs     — PUBLISH, PUBSUB subcommands
- acl.rs        — AUTH, ACL subcommands
- vector.rs     — VADD/VSIM/VREM/VGET/VCARD/VDIM/VINFO (feature-gated)
- protobuf.rs   — all PROTO* commands (feature-gated)

mod.rs is also added to connection/mod.rs so the module path resolves
correctly; execute.rs imports exec via `use super::exec`.

zero warnings, zero errors (cargo check -p ember-server).
all command-describing data now lives in one crate: enum variants,
attribute methods (is_write, acl_categories), and wire-protocol metadata
(arity, flags, key positions) are all in ember-protocol.

adding a new command means editing ember-protocol and one match arm in
execute.rs — no more two separate places to update.

execute.rs call site is now a one-liner:
  ember_protocol::command::table::handle_command_cmd(...)
@kacy kacy merged commit c72b7f1 into main Feb 27, 2026
5 of 8 checks passed
@kacy kacy deleted the refactor/execute-split branch February 27, 2026 18:56
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