Skip to content

refactor: route single-key commands in one place - #417

Merged
kacy merged 1 commit into
mainfrom
refactor/one-routing-table
Sep 24, 2026
Merged

kacy merged 1 commit into
mainfrom
refactor/one-routing-table

Conversation

@kacy

@kacy kacy commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Single-key commands were turned into shard requests in two places:

  • prepare_command in dispatch.rs handles pipelines and every single command sent on its own, which is the common case. Each command maps to a ShardRequest plus a ResponseTag.
  • The exec/*.rs functions called from execute handle transactions, the special connection modes and the fallback. Each command maps to the same ShardRequest plus its own response function.

About 90 commands existed in both, and the copies had drifted:

  • Keyspace notifications were only in the exec copies. With notify-keyspace-events on, a plain SET, SADD, EXPIRE, HSET, ZADD, LPUSH or RPUSH published nothing. Only the same command inside MULTI did.
  • The key and value size limits (max-key-len, max-value-len) were only checked in prepare_command. A SET inside MULTI skipped them.

Now:

  • connection/route.rs has one route() that maps each single-key command to a Route: the shard, request and response tag, plus the keyspace event to publish on success. Both paths call it. execute sends the request and resolves it with the same resolve_shard_response.
  • A route's Notify publishes when the reply is not an error or nil. For SADD, ZADD, EXPIRE and PEXPIRE it also requires a count above zero, so nothing is published when nothing changed. That matches what the exec copies did. PEXPIRE now publishes expire, as in Redis. It published nothing before.
  • process runs validate_command_sizes like prepare_command.
  • The routed variants stay listed in execute's match, returning an internal error, so the match is still exhaustive and a new command can't compile without a handler. The "vector support not compiled" reply for builds without the feature is unchanged.
  • The duplicate exec functions and the response helpers only they used are removed: about 1,500 lines.

A new integration test checks that a lone SET publishes its keyspace event. Clippy is clean without features, with protobuf, and with vector. The integration suite passes except the CLI tests, which need the ember-cli binary built.

About 90 single-key commands were mapped to shard requests twice: in
prepare_command for pipelines and single commands, and in exec/ for
transactions and the special connection modes. The two had drifted. The
pipelined path never published keyspace events, and the serial path
skipped the key and value size limits. route() now maps each command
once for both paths, carries its keyspace event, and the size check
runs on both paths.
@kacy
kacy merged commit 1539daf into main Sep 24, 2026
12 checks passed
@kacy
kacy deleted the refactor/one-routing-table branch September 24, 2026 21:26
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