Enforce value to be stored / returned as `json.marshal` in `set` cmd via Http protocol
Steps to reproduce
curl --location 'http://localhost:8082/set' \
--header 'Content-Type: application/json' \
--header 'Cache-Control: no-cache' \
--data '{
"key": "foo",
"value": {
"foo": {
"bar": "fooBar"
}
}
}'
curl --location 'http://localhost:8082/get' \
--header 'Content-Type: application/json' \
--header 'Cache-Control: no-cache' \
--data '{
"key": "foo"
}'
Expected output
"{"foo":{"bar":"fooBar"}}"
Observed output
"map[foo:map[bar:fooBar]]"
Suggestion
Please ensure that the value is properly serialized using json.Marshal before being sent as a response in the HTTP protocol.
Another Solution (Not Recommended, but Supported by Redis)
Redis does allow storing JSON-like values using the SET command. If clients attempt to set a key with a JSON object directly, they will encounter an error due to invalid arguments.
To store JSON values, clients must manually stringify the value before passing it to the SET command.
If a client provides a JSON object without stringifying it, the server should return an error indicating invalid arguments. It's generally advisable to use a JSON.SET for handling JSON data.
- this should be expected from Dice via HTTP protocol
Expectations for resolution
This issue will be considered resolved when the following things are done
- changes in the
dicecode to meet the expected behavior - addition of relevant test case to ensure we catch the regression
You can find the tests under the tests directory of the dice repository and the steps to run are in the README file. Refer to the following links to set up DiceDB and Redis 7.2.5 locally
can i take this up ?
Hey, I am fairly new to this project and I want to take this opportunity to get into contributing to DiceDB. Can I take up this task and return with a PR?
In expected response we need a json response or a json string?
{
"foo": {
"bar": 1
}
}
or
"{"foo":{"bar":"fooBar"}}"
In expected response we need a json response or a json string?
{ "foo": { "bar": 1 } }or
"{"foo":{"bar":"fooBar"}}"
strigified response 2nd one
@vinitparekh17 Is it fine if the stringified version has escape characters in response?
Created a PR here - https://github.com/DiceDB/dice/pull/757/files
cc: @lucifercr07