Skip to content
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

Python: adds JSON.RESP command #2451

Merged
merged 3 commits into from
Oct 29, 2024
Merged

Python: adds JSON.RESP command #2451

merged 3 commits into from
Oct 29, 2024

Conversation

shohamazon
Copy link
Collaborator

@shohamazon shohamazon commented Oct 14, 2024

Issue link

This Pull Request is linked to issue (URL): #645

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Commits will be squashed upon merging.

@Yury-Fridlyand
Copy link
Collaborator

Some of my comments caused by improper understanding of how command works.

> JSON.RESP k1 .address
1) {
2) 1) "street"
   2) "21 2nd Street"
3) 1) "city"
   2) "New York"
4) 1) "state"
   2) "NY"
5) 1) "zipcode"
   2) "10021-3100"

That what's GLIDE core should return:

1# "street" => "21 2nd Street"
2# "city" => "New York"
3# "state" => "NY"
4# "zipcode" => "10021-3100"

and a GLIDE client should return a map/dict then.
Otherwise we violate data integrity on client-server-client round trip.

Example (expected):

object = {"firstName":"John","lastName":"Smith","age":27,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"}}
await json.set(glide_client, key, ".", OuterJson.dumps(json_value))

response = await json.resp(glide_client, key, ".address")

assert response == object["address"]

@shohamazon
Copy link
Collaborator Author

Some of my comments caused by improper understanding of how command works.

> JSON.RESP k1 .address
1) {
2) 1) "street"
   2) "21 2nd Street"
3) 1) "city"
   2) "New York"
4) 1) "state"
   2) "NY"
5) 1) "zipcode"
   2) "10021-3100"

That what's GLIDE core should return:

1# "street" => "21 2nd Street"
2# "city" => "New York"
3# "state" => "NY"
4# "zipcode" => "10021-3100"

and a GLIDE client should return a map/dict then. Otherwise we violate data integrity on client-server-client round trip.

Example (expected):

object = {"firstName":"John","lastName":"Smith","age":27,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"}}
await json.set(glide_client, key, ".", OuterJson.dumps(json_value))

response = await json.resp(glide_client, key, ".address")

assert response == object["address"]

I dont understand why? we have json.get for this

@Yury-Fridlyand Yury-Fridlyand added the python Python wrapper label Oct 19, 2024
@Yury-Fridlyand
Copy link
Collaborator

As discussed with the team, no value conversion needed.

Optional[Union[bytes, int, List[Optional[Union[bytes, int]]]]]
]:
"""
Retrieve the JSON value at the specified `path` within the JSON document stored at `key`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

please return \ns from docs.

@shohamazon shohamazon mentioned this pull request Oct 29, 2024
6 tasks
@shohamazon
Copy link
Collaborator Author

As discussed with the team, no value conversion needed.

ohh missed that

Optional[Union[bytes, int, List[Optional[Union[bytes, int]]]]]
]:
"""
Retrieve the JSON value at the specified `path` within the JSON document stored at `key`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's no external docs to refer to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope, valkey doesnt have docs for the modules commands
we do have the aws docs tho https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/json-resp.html

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets add, won't hurt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will add it later with the rest of the commands, as no one has any external doc currently

async def test_json_resp(self, glide_client: TGlideClient):
key = get_random_string(5)

json_value = '{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14, "nullVal": null}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we randomize it a bit?

Signed-off-by: Shoham Elias <[email protected]>
Signed-off-by: Shoham Elias <[email protected]>
Copy link
Collaborator

@avifenesh avifenesh left a comment

Choose a reason for hiding this comment

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

One comment. Looks good!!

@shohamazon shohamazon merged commit 2284c75 into release-1.2 Oct 29, 2024
16 checks passed
@shohamazon shohamazon deleted the python/json.resp branch October 29, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Python wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants