Skip to content

Python: adds JSON.ARRAPPEND command - #2382

Merged
shohamazon merged 5 commits into
release-1.2from
python/json.append
Oct 29, 2024
Merged

shohamazon merged 5 commits into
release-1.2from
python/json.append

Conversation

@shohamazon

Copy link
Copy Markdown
Collaborator

No description provided.

@shohamazon
shohamazon requested a review from a team as a code owner October 2, 2024 11:56
Comment thread python/python/glide/async_commands/server_modules/json.py Outdated
Examples:
>>> from glide import json as valkeyJson
>>> import json
>>> await redisJson.set(client, "doc", "$", '{"a": 1, "b": ["one", "two"]}')

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
>>> await redisJson.set(client, "doc", "$", '{"a": 1, "b": ["one", "two"]}')
>>> await valkeyJson.set(client, "doc", "$", '{"a": 1, "b": ["one", "two"]}')

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

need to fix all this doc

@shohamazon shohamazon added the python 🐍 Python wrapper label Oct 2, 2024
For legacy path (`path` doesn't start with `$`):
Returns the length of the new array after appending `values` to the array at `path`.
If multiple paths match, the length of the last updated array is returned.
If the JSON value at `path` is not a array of if `path` doesn't exist, an error is raised.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
If the JSON value at `path` is not a array of if `path` doesn't exist, an error is raised.
If the JSON value at `path` is not a array or if `path` doesn't exist, an error is raised.

Comment thread python/python/glide/async_commands/server_modules/json.py
@shohamazon
shohamazon changed the base branch from main to release-1.2 October 10, 2024 13:13
@shohamazon shohamazon mentioned this pull request Oct 10, 2024
22 tasks
) -> TJsonResponse[int]:
"""Appends one or more `values` to the JSON array at the specified `path` within the JSON document stored at `key`.

See https://valkey.io/commands/json.append/ for more details.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This link is not found. Do we use https://redis.io/docs/latest/commands/json.arrappend/ instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

forgot to remove it, you can ignore

@shohamazon
shohamazon requested a review from yipin-chen October 17, 2024 16:14
@yipin-chen

Copy link
Copy Markdown
Collaborator

Please update CHANGELOG too.

client: TGlideClient,
key: TEncodable,
values: List[TEncodable],
path: Optional[TEncodable] = None,

@jamesx-improving jamesx-improving Oct 18, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

path is not optional for JSON.ARRAPPEND. Ref: https://docs.aws.amazon.com/memorydb/latest/devguide/json-arrappend.html

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

True, but it is optional is redis , wasn't sure what I'm supposed to do 🙁

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should ignore redis impl for the module

@shohamazon

Copy link
Copy Markdown
Collaborator Author

Please update CHANGELOG too.

Adding at the end of every pr

Signed-off-by: Shoham Elias <shohame@amazon.com>
Signed-off-by: Shoham Elias <shohame@amazon.com>
Comment thread python/python/glide/async_commands/server_modules/json.py Outdated
Comment thread python/python/glide/async_commands/server_modules/json.py Outdated
Comment thread python/python/glide/async_commands/server_modules/json.py Outdated

@ikolomi ikolomi 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.

On condition that not having path as Optional is not a bug

async def arrappend(
client: TGlideClient,
key: TEncodable,
path: TEncodable,

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.

why isnt the path an optional per docs?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

optional in redis, not aws, the decision was to stick with aws implementation

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.

Can you explain that?
If I'm using json with a regular Valkey-server with json, not cloud provided server, is it optional?

@shohamazon shohamazon Oct 29, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it is, not sure what to do

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.

As I see it, optional. It doesn't block AWS users, they just need to have it documented to know that for them, it's a must.
We would rather not block other user types. Tomorrow we might have some user open an issue on it.
If there's a real conflict between implementations, we can discuss with what to stick or create two APIs for the different cases.
But we would rather support all cases when those are possible together with no real issue.
Misuse is always possible, like users with a lower version using the API available in a higher version. We don't block all users from using the API, since we have some version preferences.
We can consider more sophisticated ways if you think it's not perfect, but it requires some thinking.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In particular, the usage of this command without path is quite a narrow case: it indicates that the entire JSON is just an array at its root. I would say this is, to some degree, the justification of AWS JSON module making path mandatory.

Comment thread python/python/glide/async_commands/server_modules/json.py Outdated
Signed-off-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com>
Signed-off-by: Shoham Elias <shohame@amazon.com>
Signed-off-by: Shoham Elias <shohame@amazon.com>
@shohamazon
shohamazon merged commit 1e0476c into release-1.2 Oct 29, 2024
@shohamazon
shohamazon deleted the python/json.append branch October 29, 2024 10:23
affonsov pushed a commit that referenced this pull request Aug 21, 2026
---------

Signed-off-by: Shoham Elias <shohame@amazon.com>
Signed-off-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com>
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.

7 participants