Skip to content

adapter: split redis.go / redis_compat_commands.go into cohesive files (no behavior change) - #956

Merged
bootjp merged 5 commits into
mainfrom
refactor/split-adapter-redis
Jun 24, 2026
Merged

adapter: split redis.go / redis_compat_commands.go into cohesive files (no behavior change)#956
bootjp merged 5 commits into
mainfrom
refactor/split-adapter-redis

Conversation

@bootjp

@bootjpbootjp commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Behavior-preserving refactor that splits the two largest Redis adapter files into cohesive, same-package (adapter) files. This is pure code movement: types/functions/methods/consts were relocated verbatim (comments moved with their code). No signatures, logic, names, or semantics changed.

  • adapter/redis.go: 4,483 -> 935 lines (core entry kept: server struct, options, NewRedisServer, lifecycle, dispatch infra, conn state, metrics/error helpers, ping, validateCmd, pub/sub fan-out).
  • adapter/redis_compat_commands.go: 5,434 -> 81 lines (now holds only the shared top-level const block).

File map (region -> new file, with line counts)

Moved out of redis.go:

RegionNew fileLines
SET/GET option types + parsing, set/get/del/exists/keys-string core, leader-expiry helpersredis_strings.go644
KEYS/scan helpers, pattern matching, visible-user-key encodingredis_keys.go320
txnContext + all txn methods, MULTI/DISCARD/EXEC, runTransaction, runTransactionWithDedup, dispatchExecReuse, firstExecAttempt, txnStartTS, txnApplyHandlersredis_txn.go1,526
Leader proxying (txn + per-key) and go-redis result writersredis_proxy_leader.go375
List ops + dedup path (listPushCore, listPushCoreWithDedup, dispatchListPushReuse, pop/range/trim)redis_lists.go836

Moved out of redis_compat_commands.go:

RegionNew fileLines
INFO/CLIENT/COMMAND/HELLO/SELECT/TYPE/SCAN/PUBLISH/SUBSCRIBE/DBSIZE/FLUSH*/PUBSUBredis_server_cmds.go795
SETEX/GETDEL/SETNX, TTL/PTTL/EXPIRE/PEXPIRE familyredis_expire_cmds.go346
SADD/SREM/SISMEMBER/SMEMBERS/PFADD/PFCOUNT + set helpersredis_set_cmds.go632
HSET/HGET/HDEL/HEXISTS/HLEN/HINCRBY/HGETALL/INCR + hash helpersredis_hash_cmds.go927
ZADD/ZINCRBY/ZRANGE/ZREM/ZREMRANGEBYRANK/BZPOPMIN + zset fast-path helpersredis_zset_cmds.go1,155
XADD/XTRIM/XRANGE/XREVRANGE/XREAD/XLEN + stream parsing/scan helpersredis_stream_cmds.go1,492
LPUSH/LTRIM/LINDEX (list cmds living in compat file)redis_lists.go (shared dest)

buildRouteMap (the dispatch table) was already in redis_command_specs.go and was left untouched.

No behavior change

Pure move. Verified two independent ways:

  1. go doc -all ./adapter identical — captured the exported API surface against the worktree base (via git stash of the source files) and after the split; diff reports no differences.
  2. Code-line multiset identical — stripping package/import blocks from all 13 files and comparing the multiset of non-blank code lines against the two originals: 9,144 lines on both sides, 0 missing, 0 extra. The +147 net line delta in the raw diff is entirely the added package adapter + import (...) boilerplate in the 11 new files.

Imports were recomputed per file and the source-file alias conventions preserved exactly: redis.go-derived files keep "github.com/cockroachdb/errors" unaliased; redis_compat_commands.go-derived files keep stdlib "errors" plus cockerrors "github.com/cockroachdb/errors", and redis_stream_cmds.go keeps google.golang.org/grpc/{codes,status}.

Jepsen-guarded blocks moved intact

The recently-merged one-phase-dedup default-flip config options (#943) — WithOnePhaseTxnDedup / WithStandaloneSetDedup — were left in place in redis.go core. The txn/dedup machinery (txnContext + methods, runTransaction, runTransactionWithDedup, dispatchExecReuse, firstExecAttempt, txnStartTS, txnApplyHandlers) was moved as one intact contiguous block into redis_txn.go; the list-dedup path (listPushCoreWithDedup / dispatchListPushReuse / listPushCore) was moved intact into redis_lists.go. No internals of these blocks were reorganized.

Verification evidence

go build ./... -> ok
gofmt -l adapter/ -> (empty)
go vet ./adapter/ -> ok
golangci-lint --config=.golangci.yaml run ./adapter/ -> 0 issues
go test -race -count=1 -run 'TestRedis|Redis' \
-timeout 900s ./adapter/ -> ok 252.675s
go doc -all ./adapter (base vs after) -> identical
code-line multiset (base vs after) -> identical (9144, 0 missing, 0 extra)

Five-lens self-review (pure move)

  1. Data loss — No semantic change. Raft propose/apply, FSM, snapshot, TTL, and dedup code is byte-identical and merely relocated; the code-line multiset and go doc checks prove no statement was dropped or altered. No new error-handling paths.
  2. Concurrency / distributed failures — No change to locking, leader-change handling, OCC resolution, or the lease-read window; the txn/list dedup blocks (the parts Jepsen guards) moved intact. go test -race on the full Redis suite passes.
  3. Performance — No hot-path edits, no new allocations, no extra Raft round-trips; identical machine code modulo file boundaries. No HLC Next() path touched.
  4. Data consistency — MVCC visibility, OCC commit-ts ordering, HLC ceiling, and adapter wire semantics are unchanged (same statements, same order). go doc parity confirms the public contract is unchanged.
  5. Test coverage — No new branches were introduced, so no new tests are required; existing co-located *_test.go files were not split and continue to exercise the moved code (full TestRedis|Redis race suite green).

Summary by CodeRabbit

  • New Features
    • Added full support for core Redis commands across strings, lists, sets, hashes, sorted sets, and streams (including range queries and ZSET/ZPOP-style pops).
    • Implemented Redis-compatible TTL/expiration handling (EX/PX, NX/XX, GET semantics) and leader-aware routing for accurate reads/writes.
    • Added pattern-based key discovery (KEYS/SCAN) and Redis MULTI/EXEC/DISCARD transactions with correct staging and execution behavior.
    • Extended server introspection, client metadata, and Pub/Sub monitoring.
  • Bug Fixes
    • Improved deletion correctness for wide-column sorted sets during removals.
  • Tests
    • Added coverage for KEYS argument validation and wide-column ZREM cleanup behavior.

Loading
Sign up for freeto 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.

2 participants

@bootjp