Skip to content

Conversation

KoKimSS
Copy link
Contributor

@KoKimSS KoKimSS commented Aug 12, 2025

This PR adds String-based overloads for JSON commands to eliminate unnecessary conversion overhead between String ↔ JsonValue objects, addressing performance concerns raised in the feature request #3369.

Important Note

The existing JSON API assumes users only work with JsonValue objects. In certain cases, applications might want to provide a String interface instead, because otherwise they'd have to convert from string to JsonValue and then the driver would convert back to String and then to a byte array.

This approach provides String-based overloads that work directly with String input/output parameters, instead of JsonValue objects, eliminating unnecessary conversions while maintaining full backward compatibility.

Performance Benefits

  • Before: String → JsonValue.of() → toString() → getBytes() → ByteBuffer.wrap() → array()
  • After: String → getBytes() (direct conversion)
  • Result: Eliminates unnecessary object creation and conversion steps

Changes Made

New String Overload Methods Added

  • jsonArrappend(K key, JsonPath jsonPath, String... jsonStrings)
  • jsonArrindex(K key, JsonPath jsonPath, String jsonString, JsonRangeArgs range)
  • jsonArrinsert(K key, JsonPath jsonPath, int index, String... jsonStrings)
  • jsonMerge(K key, JsonPath jsonPath, String jsonString)
  • jsonSet(K key, JsonPath jsonPath, String jsonString, JsonSetArgs options)
  • jsonStrappend(K key, JsonPath jsonPath, String jsonString)

Core Implementation

  • RedisJsonCommandBuilder: Added String overload methods with direct string-to-bytes conversion
  • RedisJsonAsyncCommands: Updated async interface with String overloads
  • RedisJsonReactiveCommands: Updated reactive interface with String overloads
  • RedisJsonCommands: Updated sync interface with String overloads
  • AbstractRedisAsyncCommands: Added implementation for all String overloads
  • AbstractRedisReactiveCommands: Added reactive implementations

Testing

  • RedisJsonCommandBuilderUnitTests: Added comprehensive unit tests for all String overload methods
  • Command encoding verification for both custom JsonPath and ROOT_PATH scenarios
  • Direct string encoding optimization validation

- Add String overloads for jsonArrappend, jsonArrindex, jsonArrinsert
- Add String overloads for jsonMerge, jsonSet, jsonStrappend
- Implement direct String-to-bytes conversion in RedisJsonCommandBuilder
- Update Async, Reactive, and Sync interfaces consistently
- Eliminate String → JsonValue → String → bytes conversion overhead
- Add unit tests for all String overload methods
- Verify direct string encoding optimization
- Test both custom JsonPath and ROOT_PATH scenarios
- Validate command construction for all String-based JSON operations
- Remove JavaDoc comments from RedisJsonCommandBuilder String methods to match class conventions
- Update @author entries to use full names (SeungSu Kim)
- Fix @SInCE annotation from 6.5 to 6.9 for new String overload methods
- Restore blank lines and fix spacing to maintain consistent formatting
- Align documentation style with existing codebase patterns
@a-TODO-rov
Copy link
Contributor

Hey @KoKimSS
Thank you very much for you contribution.
I pushed one commit to finish what you've started.
After @tishun takes a look, we can wrap this issue.

@a-TODO-rov a-TODO-rov requested a review from tishun September 1, 2025 15:54
@KoKimSS
Copy link
Contributor Author

KoKimSS commented Sep 1, 2025

Hey @KoKimSS Thank you very much for you contribution. I pushed one commit to finish what you've started. After @tishun takes a look, we can wrap this issue.

Thank you so much! I'm really happy to contribute to lettuce, which I've been using regularly. Looking forward to @tishun's review to get this wrapped up!

Copy link
Collaborator

@tishun tishun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just the @since annotation needs to be changed imho

@a-TODO-rov a-TODO-rov merged commit c5ab6bb into redis:main Sep 2, 2025
8 checks passed
tishun pushed a commit to tishun/lettuce-core that referenced this pull request Sep 2, 2025
… (redis#3394)

* Add String-based JSON API to avoid unnecessary conversions redis#3369

- Add String overloads for jsonArrappend, jsonArrindex, jsonArrinsert
- Add String overloads for jsonMerge, jsonSet, jsonStrappend
- Implement direct String-to-bytes conversion in RedisJsonCommandBuilder
- Update Async, Reactive, and Sync interfaces consistently
- Eliminate String → JsonValue → String → bytes conversion overhead

* Add comprehensive tests for String JSON API redis#3369

- Add unit tests for all String overload methods
- Verify direct string encoding optimization
- Test both custom JsonPath and ROOT_PATH scenarios
- Validate command construction for all String-based JSON operations

* Polish JSON API documentation and formatting redis#3369

- Remove JavaDoc comments from RedisJsonCommandBuilder String methods to match class conventions
- Update @author entries to use full names (SeungSu Kim)
- Fix @SInCE annotation from 6.5 to 6.9 for new String overload methods
- Restore blank lines and fix spacing to maintain consistent formatting
- Align documentation style with existing codebase patterns

* CAE-1404 - finish String extension for JSON API

* Fix since annotation on json string API

* Rm useless comments in implementations and mark methods as Override

* Rm more comments.

* Format

---------

Co-authored-by: aleksandar.todorov <a_t_todorov@yahoo.com>
tishun pushed a commit that referenced this pull request Sep 2, 2025
…3394)

* Add String-based JSON API to avoid unnecessary conversions #3369

- Add String overloads for jsonArrappend, jsonArrindex, jsonArrinsert
- Add String overloads for jsonMerge, jsonSet, jsonStrappend
- Implement direct String-to-bytes conversion in RedisJsonCommandBuilder
- Update Async, Reactive, and Sync interfaces consistently
- Eliminate String → JsonValue → String → bytes conversion overhead

* Add comprehensive tests for String JSON API #3369

- Add unit tests for all String overload methods
- Verify direct string encoding optimization
- Test both custom JsonPath and ROOT_PATH scenarios
- Validate command construction for all String-based JSON operations

* Polish JSON API documentation and formatting #3369

- Remove JavaDoc comments from RedisJsonCommandBuilder String methods to match class conventions
- Update @author entries to use full names (SeungSu Kim)
- Fix @SInCE annotation from 6.5 to 6.9 for new String overload methods
- Restore blank lines and fix spacing to maintain consistent formatting
- Align documentation style with existing codebase patterns

* CAE-1404 - finish String extension for JSON API

* Fix since annotation on json string API

* Rm useless comments in implementations and mark methods as Override

* Rm more comments.

* Format

---------

Co-authored-by: aleksandar.todorov <a_t_todorov@yahoo.com>
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