Skip to content

Rework Redis command construction logic. - #2847

Merged
michael-grunder merged 4 commits into
developfrom
refactor.redis-cmd
Jun 4, 2026
Merged

Rework Redis command construction logic.#2847
michael-grunder merged 4 commits into
developfrom
refactor.redis-cmd

Conversation

@michael-grunder

Copy link
Copy Markdown
Member
  • Introduce a new RedisCmd struct to dynamically append RESP arguments such that we don't have to precalculate the number of arguments the command will have up front.

  • Additionally the new RedisCmd allows both a void *context pointer but also can attach avoid (ctx_dtor)(void)` destructor so we are still able to clean up any allocated context when commands fail. This moves the context cleanup out of every individual reply handler and into the generic processing wrappers.

  • Create a small group of resp_str helper functions for lower level concatination of RESP protocol data over the wire.

  • Lots of small modernization of the codebase such as using zend_string* instead of (char *, size_t) pairs.

  • Fix: Properly apply any Redis::OPT_PREFIX to both the SORT key and the STORE key in the sort command.

Comment thread cluster_library.c Fixed
Comment thread cluster_library.c Fixed
Comment thread cluster_library.c Fixed
Comment thread cluster_library.c Fixed
Comment thread cluster_library.c Fixed
Comment thread cluster_library.c Fixed
Comment thread cluster_library.c Fixed
Comment thread common.h Fixed
Comment thread library.c Fixed
@michael-grunder
michael-grunder force-pushed the refactor.redis-cmd branch 4 times, most recently from 79bc791 to 8911299 Compare May 28, 2026 20:31
@michael-grunder

Copy link
Copy Markdown
Member Author

@yatsukhnenko I won't merge this before AB testing it for backward compatibility issues but it drastically reduces the boilerplate in building commands.

It also fixes a many years long memory leak pathway (failing halfway through a transaction) because previously the wrapper method didn't know how to free the void *ctx.

One note, the reason I am passing RelayCmdCtx by value is that it is slightly more efficient than passing a pointer. Both members are pushed into registers. Also we don't need a pointer here since we can use refcounts in the most complicated handlers likehmget

Comment thread tests/RedisTest.php Outdated
Comment thread tests/RedisTest.php Outdated
Comment thread tests/TestSuite.php Outdated
* Introduce a new `RedisCmd` struct to dynamically append RESP arguments
  such that we don't have to precalculate the number of arguments the
  command will have up front.

  Additionally the new `RedisCmd allows both a `void *` context pointer
  but also can attach a `void (*ctx_dtor)(void*)` destructor so we are
  still able to clean up any allocated context when commands fail.

  This moves the context cleanup out of every individual reply handler
  and into the generic processing wrappers.

* Create a small group of `resp_str` helper functions for lower level
  concatination of RESP protocol data over the wire.

* Lots of small modernization of the codebase such as using
  `zend_string*` instead of (`char *`, `size_t`) pairs.

* Greatly simplify `crosslot` handling logic
michael-grunder and others added 3 commits June 1, 2026 20:13
Co-authored-by: Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com>
Co-authored-by: Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com>
Co-authored-by: Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com>
@michael-grunder
michael-grunder merged commit b0d534e into develop Jun 4, 2026
126 of 128 checks passed
@michael-grunder
michael-grunder deleted the refactor.redis-cmd branch June 4, 2026 19:16
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.

3 participants