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.STRLEN, JSON.STRAPPEND commands #1187

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

shohamazon
Copy link
Member

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@shohamazon shohamazon requested a review from a team as a code owner March 27, 2024 11:07
@shohamazon shohamazon changed the title Python: adds JSON.STRLEN command Python: adds JSON.STRLEN, JSON.STRAPPEND commands Mar 28, 2024
Args:
client (TRedisClient): The Redis client to execute the command.
key (str): The key of the JSON document.
path (Optional[str]): The JSONPath to specify. Default is root `$`. // TODO check (since when sending strlen "non_exiting" and strlen "non_exiting" . -> behaves the same)
Copy link
Member Author

Choose a reason for hiding this comment

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

when running the commands:

127.0.0.1:6379> json.strlen non_existing_key
(nil)
127.0.0.1:6379> json.strlen non_existing_key .
(nil)
127.0.0.1:6379> json.strlen non_existing_key $
(error) ERR could not perform this operation on a key that doesn't exist

Copy link
Member Author

Choose a reason for hiding this comment

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

so I am not really sure that default it $

Copy link
Contributor

Choose a reason for hiding this comment

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

Then remove the comment to what it defaults to, just say in the documentation that if not passed a default value will be used

CHANGELOG.md Outdated
@@ -52,6 +52,7 @@
* Core: Enabled Cluster Mode periodic checks by default ([#1089](https://github.com/aws/glide-for-redis/pull/1089))
* Node: Added Rename command. ([#1124](https://github.com/aws/glide-for-redis/pull/1124))
* Python: Added JSON.TOGGLE command ([#1184](https://github.com/aws/glide-for-redis/pull/1184))
* Python: Added JSON.STRLEN, JSON.STAPPEND commands ([#1187](https://github.com/aws/glide-for-redis/pull/1187))
Copy link
Contributor

Choose a reason for hiding this comment

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

move it up to the right version

path (Optional[str]): The JSONPath to specify. If not passed, a default value will be used.

Returns:
TJsonResponse[Optional[int]]: For JSONPath (`path` starts with `$`), returns a list of integer replies for every possible path,
Copy link
Contributor

Choose a reason for hiding this comment

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

lets simplify it by splitting the return to two sections:

 Returns:
        TJsonResponse[Optional[int]]: 
                For JSONPath (`path` starts with `$`):
                   Returns a list of integer replies for every possible path, indicating the length of the JSON string value, or None for JSON values matching the path that are not string. If `key` doesn't exist, an error is raised.
                For legacy path (`path` doesn't start with `$`):
                   Returns the length of the JSON value at `path` or None if `key` doesn't exist. If the JSON value at `path` is not a string of if `path` doesn't exist, an error is raised, If `key` doesn't exist, None is returned.

Copy link
Contributor

Choose a reason for hiding this comment

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

please do it for all

with pytest.raises(RequestError):
assert await json.toggle(redis_client, "non_exiting_key", "$")

@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
Copy link
Contributor

Choose a reason for hiding this comment

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

what about tests without specifying path?

Args:
client (TRedisClient): The Redis client to execute the command.
key (str): The key of the JSON document.
path (Optional[str]): The JSONPath to specify. If not passed, a default value will be used.
Copy link
Contributor

@barshaul barshaul Apr 24, 2024

Choose a reason for hiding this comment

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

lets try to stick with the document in ElastiCache docs, if it fits also for OSS
https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/json-strlen.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants