redis / go-redis

Redis Go client
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
19.61k stars 2.31k forks source link

JSON-Set : Not able to update fields with string values #2965

Open Prophet0fRegret opened 3 months ago

Prophet0fRegret commented 3 months ago

JSON-Set command is not able to update the specified field in the command with the supplied value if it is a STRING. It completes successfully if the value is something other, for example, an integer.

Expected Behavior

JSON-Set should be able to update JSON fields with string values.

Current Behavior

JSON-Set is not able to update JSON fields with string values. The command returns the following error : "expected value at line 1 column 1"

Possible Solution

Error is returned when entering the following command in CLI or from the lib : JSON:SET <key> <path.subpath> <STRING value to be set>

But no errors are returned when the same operation is tried using the following command from the CLI : JSON:SET <key> <path.subpath> '"<STRING value to be set>"'

The issue gets fixed if you enclose the string value with double-quotes (""), & then also enclose it within single-quotes('). Does not work if you try either of them, or none.

Steps to Reproduce

For the record, I believe I am on the latest version of the package, which is v9.5.1, at the time of reporting this bug.

  1. Try to set a new JSON object using a similar command : JSON.SET doc . '{"a":"2"}'
  2. Try to update the key, here, a, with a similar command : JSON.SET doc .a "7"
  3. Receive the above mentioned error

Context (Environment)

I am trying to update a field in an existing JSON document in REDIS. Using the go-redis package, I am able to set a new JSON object with the JsonSET() function. But when trying to utilise the same function to update a specific field with a string value, it gives the error.

I am not able to find any other alternative function which allows to update the fields. When faced with the same issue on the CLI, I tried different combinations and deduced that the string value that I am trying to update for the field needs to be enclosed in both th double-quotes and single-quotes for it to work.

Possible Implementation

I believe the change should be in the way the string is being parsed and sent to REDIS. I tried some stuff, like adding escape characters, but it still gives the same issue.