Adding a registry that maps command names to their flags#4332
Adding a registry that maps command names to their flags#4332
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a command flags feature to the Jedis library by adding a static registry that maps Redis command names to their flags. The implementation retrieves command metadata from a Redis server and automatically generates flag mappings.
- Adds a code generator that connects to Redis servers to extract command metadata and generate flag mappings
- Implements a static command flags registry in
CommandObject.javawith comprehensive command coverage - Provides a
getFlags()method for runtime flag lookup with optimized memory usage through shared EnumSet instances
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/test/java/redis/clients/jedis/codegen/README.md | Documentation for the command flags registry generator tool |
| src/test/java/redis/clients/jedis/codegen/CommandFlagsRegistryGenerator.java | Code generator that retrieves Redis command metadata and updates the static registry |
| src/main/java/redis/clients/jedis/CommandObject.java | Core implementation with CommandFlag enum, static registry, and getFlags() method |
| pom.xml | Maven configuration to exclude code generators from test execution |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/test/java/redis/clients/jedis/codegen/CommandFlagsRegistryGenerator.java
Outdated
Show resolved
Hide resolved
src/test/java/redis/clients/jedis/codegen/CommandFlagsRegistryGenerator.java
Outdated
Show resolved
Hide resolved
src/test/java/redis/clients/jedis/codegen/CommandFlagsRegistryGenerator.java
Outdated
Show resolved
Hide resolved
e8157fa to
51c62d5
Compare
Test Results 281 files +1 281 suites +1 11m 41s ⏱️ -6s Results for commit fdf00b5. ± Comparison against base commit 4776709. This pull request skips 600 tests.♻️ This comment has been updated with latest results. |
ggivo
left a comment
There was a problem hiding this comment.
Looks good.
For better traceability, I would suggest placing the generated code in a dedicated file.
Additionally, wrapping command metadata in in an interface (CommandMetadataRegistry.getFlag()) and providing it as an configurabel instance within CommandObject would be beneficial. The auto-generated registry can serve as the default, but users could replace it with a custom implementation if needed — for example, dynamically loading it from the server or providing a user-defined version.
atakavci
left a comment
There was a problem hiding this comment.
Adding the version of server - the generator running against- as part of generated content would be nice as well.
|
|
||
| public class CommandObject<T> { | ||
|
|
||
| /** |
There was a problem hiding this comment.
lets not do this and put everything into a seperate completely auto-generate class like CommandFlagRegistry or some provider class,, and use generated content at once without need of regex or any other searching/parsing. Then just consume it from CommandObject as needed.
- Add new interface and move CommandFlag enum there - Generate StaticCommandFlagsRegistry instead of embedding generated code into CommandObject - Allow passing custom CommandFlagsRegistry to ClusterClientBuilder
| public EnumSet<CommandFlag> getFlags(ProtocolCommand cmd) { | ||
| byte[] raw = cmd.getRaw(); | ||
| String commandName = SafeEncoder.encode(raw).toUpperCase(); | ||
| return COMMAND_FLAGS_REGISTRY.getOrDefault(commandName, EMPTY_FLAGS); | ||
| } |
There was a problem hiding this comment.
This does not seem to work for subcommands like "CLUSTER INFO", "CONFIG GET" ...
In this case, ProtocolCommand is actually only "CLUSTER"
There was a problem hiding this comment.
I've addressed this problem. See my latest commit ff09e22
… im/introduce-command-flags
… im/introduce-command-flags
…rom actual implementation (#4345) * (clean up) Extract generated registry initialization * regenerate after clean up * reformat
Introduces command flags to simplify command routing.