Skip to content

Add String-based JSON API to avoid unnecessary conversions (#3369) #3394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

KoKimSS
Copy link

@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
@KoKimSS KoKimSS force-pushed the feature/json-string-api branch from 7f263e2 to cd1e1ae Compare August 13, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants