refactor: split execute.rs into exec/ sub-modules + move COMMAND_TABLE to ember-protocol#340
Merged
refactor: split execute.rs into exec/ sub-modules + move COMMAND_TABLE to ember-protocol#340
Conversation
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(...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
execute.rswas 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.rsis now a ~580-line thin router that constructs anExecCtxand dispatches eachCommandvariant to its owning sub-moduleexec/directory with 13 focused files:strings,keyspace,server,lists,sorted_sets,hashes,sets,cluster,pubsub,acl,vector,protobuf, and a sharedmod.rsExecCtx<'a>bundles engine + ctx + pubsub + slow_log + client_id — zero-cost, just cleaner ergonomics than 5 separate parameters in every helperCOMMAND_TABLE+handle_command_cmdmoved toember-protocol/src/command/table.rs— all command-describing data (enum variants, attribute methods, wire-protocol metadata) now lives in one crateno 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-serverandcargo check -p ember-protocolboth pass cleancargo fmtappliedCOMMAND COUNTandCOMMAND INFO GETreturn identical values to pre-refactorPING,GET,SET,ZADD,HSETall behave identicallydesign considerations
ExecCtxvisibility ispub(in crate::connection)— accessible to all exec sub-modules andexecute.rs, invisible outside the connection module. sub-module functions arepub(in crate::connection)soexecute.rscan callexec::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.