Skip to content

Draft API for connection and template layers for Redis JSON commands#3327

Open
Dgramada wants to merge 22 commits into
spring-projects:mainfrom
Dgramada:topic/JSON-API-draft-for-connection-and-template-layer
Open

Draft API for connection and template layers for Redis JSON commands#3327
Dgramada wants to merge 22 commits into
spring-projects:mainfrom
Dgramada:topic/JSON-API-draft-for-connection-and-template-layer

Conversation

@Dgramada

Copy link
Copy Markdown
Contributor

Provides a draft version of how the JSON template and connection layer API should look like. The purpose of this PR is to receive feedback and to get a better feeling of what should Spring Data Redis provide for users that would like to use Redis JSON.

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 11, 2026
@mp911de mp911de marked this pull request as draft March 12, 2026 14:03

@onobc onobc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👋🏻 @Dgramada ,

Thanks for the PR - it is great to see the feature being added. I have left a few comments to address / points to discuss.

Comment thread src/main/java/org/springframework/data/redis/core/json/JsonArrayRange.java Outdated
Comment thread src/main/java/org/springframework/data/redis/connection/RedisJsonCommands.java Outdated
Comment thread src/main/java/org/springframework/data/redis/core/json/JsonPath.java Outdated
@Dgramada

Copy link
Copy Markdown
Contributor Author

If the interfaces are acceptable, I could close this issue and create a separate one that introduces them alongside their implementations and testing. Would you prefer this approach or would you like me to extend this PR?

Comment thread src/main/java/org/springframework/data/redis/core/json/JsonPath.java Outdated
@onobc

onobc commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

If the interfaces are acceptable,
I do - they are at a nice simple starting point.

I could close this issue and create a separate one that introduces them alongside their implementations and testing.
Would you prefer this approach or would you like me to extend this PR?

I would just rock this PR (continue on from this point).

Thank you for the quick turnaround - I was on PTO - sorry for the delay.

@Dgramada Dgramada force-pushed the topic/JSON-API-draft-for-connection-and-template-layer branch from 0680f61 to 275ca3e Compare March 24, 2026 12:56
…perations.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
@Dgramada Dgramada force-pushed the topic/JSON-API-draft-for-connection-and-template-layer branch from 275ca3e to 2f2f6d3 Compare March 24, 2026 13:02
Comment thread src/main/java/org/springframework/data/redis/connection/RedisJsonCommands.java Outdated
Comment thread src/main/java/org/springframework/data/redis/connection/RedisJsonCommands.java Outdated
…s. Added connection layer logic for blocking layer. Removed redundant asserts in RedisJsonCommands default methods.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Comment thread src/main/java/org/springframework/data/redis/connection/RedisJsonCommands.java Outdated
Comment thread src/main/java/org/springframework/data/redis/core/JsonOperations.java Outdated
…urn type in multiple RedisJsonCommands methods.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
…sonCommands overload to RedisConnectionUnitTests. Updated @SInCE to 4.1.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
@onobc onobc self-requested a review March 27, 2026 19:43

@onobc onobc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👋🏻 @Dgramada I left a couple comments to address. Thanks.

Comment thread src/main/java/org/springframework/data/redis/connection/RedisJsonCommands.java Outdated
Comment thread src/main/java/org/springframework/data/redis/connection/RedisJsonCommands.java Outdated
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
…mmands.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
@Dgramada Dgramada marked this pull request as ready for review April 22, 2026 14:35
…Unmarked.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
* @see <a href="https://redis.io/docs/latest/commands/json.arrappend/">Redis Documentation: JSON.ARRAPPEND</a>
* @since 4.2
*/
List<Long> jsonArrAppend(byte @NonNull [] key, @NonNull String path, @NonNull String @NonNull... values);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's review if the @NonNull String @NonNull... values argument should be of type String or a different approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lettuce exposes String and JsonValue overloads. Jedis is typed as Object but, at runtime, is invoked with a String and dispatched to its String branch. Both drivers convert values to UTF‑8 bytes and send as is, without Jackson/Gson serialization. Validation happens server-side in the RedisJSON module and the call succeeds if the bytes form a valid JSON document.

Passing raw null as a parameter value throws an exception in both drivers once they start encoding the value.
POJOs would also fail as the class wouldn't pass through an actual JSON serialization.

In my opinion, the best fit would be to accept a String parameter which represents a JSON value.

Example:

"5" -> JSON number

""5"" -> JSON string

"true" -> JSON boolean

""true"" -> JSON string

"{
   "firstName": "Rand"
   "lastName": "Al'Thor",
   "address": {
      "name": "Two Rivers"
   }
}" -> JSON object where address points to another JSON object value

"{
   "firstName": "Rand"
   "lastName": "Al'Thor",
   "address": "{
      "name": "Two Rivers"
   }"
}" -> JSON object where address points to a JSON string value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A plain String doesn't carry sufficient semantics here, I'm afraid. Every caller arriving at this API would end up asking themselves the very same question, having to dive into the driver details in order to reconstruct the actual contract and that's a recurring tax we'd rather not impose in the first place.

This may feel counterintuitive at present, but I tend towards generalizing the JsonValue notion instead (as in JsonOperations.JsonValue). We've effectively arrived at such an abstraction on the template API already; the natural next step is to push the core abstraction down to the connection level quite along the lines of the stream support in org.springframework.data.redis.connection.stream. As things stand, it's really only the JsonValue.as methods that betray a template-API nature.

Revisiting the template API design with our present insights, I'd refine JsonValue towards a JsonResult extends ….connection.json.JsonValue arrangement on the template side, moving the remaining pieces into the connection.json package proper.

JsonValue itself would then define static factory methods: JsonValue.literal(Number) along with int/long/double/String overloads, JsonValue.nullValue(), and JsonValue.ofJson(String) for verbatim JSON. All connection-level methods would accept JsonValue rather than a raw String accordingly.

Let me know what you think; happy to iterate on the specifics.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just to clarify, JsonValue will act as a wrapper and won't really do any parsing right? This is a good approach as it gives more leeway for the API if it needs any modification in the future.

Maybe we should use this approach for the JSONPath as well? We could wrap the string path in a JsonPath similarly to how Jedis and Lettuce do.

Comment thread src/main/java/org/springframework/data/redis/connection/RedisJsonCommands.java Outdated
Comment thread src/main/java/org/springframework/data/redis/connection/RedisJsonCommands.java Outdated
Dgramada added 2 commits May 27, 2026 16:51
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
…rently Jedis has a very inconsistent API compared to Lettuce and changes the data type. Added safely encoded strings to JedisJsonCommands for value params

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Dgramada added 3 commits May 29, 2026 14:16
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
@mp911de

mp911de commented Jun 3, 2026

Copy link
Copy Markdown
Member

I think we're closing in on a first solid design here. I'd suggest drawing some inspiration from 28f5665 (on the Json branch in this repository), particularly around JsonValue. There ought to be a JsonType (analogous to DataType) residing in the connection.json package, alongside JsonValue itself. We may well reuse JsonType later on within JsonResult.

I'd propose finalizing the JsonCommands parts first, so that we can then approach JsonOperations and JsonTemplate as a separate, second step. Splitting the effort into two pieces keeps the complexity manageable on both ends.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Comment thread src/main/java/org/springframework/data/redis/connection/json/JsonValue.java Outdated
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants