Skip to content

refactor: consolidate cluster slot checks in connection.rs - #73

Merged
kacy merged 1 commit into
mainfrom
refactor/consolidate-cluster-slot-checks
Feb 10, 2026
Merged

refactor: consolidate cluster slot checks in connection.rs#73
kacy merged 1 commit into
mainfrom
refactor/consolidate-cluster-slot-checks

Conversation

@kacy

@kacy kacy commented Feb 10, 2026

Copy link
Copy Markdown
Owner

summary

extracts a single cluster_slot_check() function that pattern-matches the command to determine its routing key(s), validates slot ownership and crossslot constraints, and returns the redirect/error frame if needed. this replaces the per-command inline checks with one call at the top of execute().

  • removed: ~130 lines of repeated 3-line (check_cluster_slot) and 7-line (check_crossslot + check_cluster_slot) blocks scattered across ~39 match arms
  • added: ~60 lines in one focused function with clear grouping (single-key, multi-key, rename, mset, passthrough)
  • net reduction of ~112 lines

what was tested

  • cargo build -p ember-server — compiles clean
  • cargo clippy --workspace -- -D warnings — no warnings
  • cargo test --workspace — all tests pass (behavior unchanged)

design considerations

the new function uses a single match on &Command to extract the routing key(s), grouping commands into four categories:

  1. single-key: 37 variants bound via ref key — delegates to cluster.check_slot()
  2. multi-key (DEL, UNLINK, EXISTS, MGET): crossslot check on all keys, then slot check on the first
  3. rename: crossslot check on [key, newkey], then slot check on key
  4. mset: extracts keys from pairs, same crossslot + slot pattern
  5. wildcard: everything else (PING, INFO, cluster commands, pubsub, etc.) returns None — no slot routing needed

the function is called once at the top of execute(), before the main dispatch match. commands that don't need slot routing fall through the wildcard arm with zero overhead (just a pattern match, no async work).

extract a single `cluster_slot_check()` function that pattern-matches
the command to find its routing key(s), performs slot ownership and
crossslot validation, and returns the redirect/error frame if needed.

this replaces ~35 identical 3-line check blocks in single-key command
arms and 4 similar 7-line blocks in multi-key arms with one call at the
top of `execute()`, removing ~130 lines of repeated boilerplate.
@kacy
kacy merged commit fbf4fe0 into main Feb 10, 2026
7 checks passed
@kacy
kacy deleted the refactor/consolidate-cluster-slot-checks branch February 10, 2026 01:25
kacy added a commit that referenced this pull request Feb 11, 2026
extract a single `cluster_slot_check()` function that pattern-matches
the command to find its routing key(s), performs slot ownership and
crossslot validation, and returns the redirect/error frame if needed.

this replaces ~35 identical 3-line check blocks in single-key command
arms and 4 similar 7-line blocks in multi-key arms with one call at the
top of `execute()`, removing ~130 lines of repeated boilerplate.
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