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 - Implement JSON.MGET command #2507

Merged
merged 13 commits into from
Nov 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def mget(
Retrieves the JSON values at the specified `path` stored at multiple `keys`.

BoazBD marked this conversation as resolved.
Show resolved Hide resolved
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command
In cluster mode, if keys in `keys` map to different hash slots, the command
will be split across these slots and executed separately for each. This means the command
is atomic only at the slot level. If one or more slot-specific requests fail, the entire
call will return the first encountered error, even though some requests may have succeeded
Expand Down
24 changes: 23 additions & 1 deletion python/python/tests/tests_server_modules/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ async def test_json_mget(self, glide_client: TGlideClient):
await json.set(glide_client, key2, "$", OuterJson.dumps(json2_value)) == OK
)

# Test with root JSONPath
result = await json.mget(
glide_client,
[key1, key2],
Expand All @@ -189,6 +190,7 @@ async def test_json_mget(self, glide_client: TGlideClient):
]
assert result == expected_result

# Retrieves the full JSON objects from multiple keys.
result = await json.mget(
glide_client,
[key1, key2],
Expand All @@ -208,6 +210,7 @@ async def test_json_mget(self, glide_client: TGlideClient):
expected_result = [b"[1.0]", b"[3.0]"]
assert result == expected_result

# Retrieves the value of the 'b' field for multiple keys.
result = await json.mget(
glide_client,
[key1, key2],
Expand All @@ -216,6 +219,7 @@ async def test_json_mget(self, glide_client: TGlideClient):
expected_result = [b'[{"a":1,"b":2.5,"c":true}]', b'[{"a":1,"b":4}]']
assert result == expected_result

# Retrieves all values of 'b' fields using recursive path for multiple keys
result = await json.mget(
glide_client,
[key1, key2],
Expand All @@ -224,6 +228,7 @@ async def test_json_mget(self, glide_client: TGlideClient):
expected_result = [b'[{"a":1,"b":2.5,"c":true},2.5]', b'[{"a":1,"b":4},4]']
assert result == expected_result

# retrieves the value of the nested 'b.b' field for multiple keys
result = await json.mget(
glide_client,
[key1, key2],
Expand All @@ -232,6 +237,15 @@ async def test_json_mget(self, glide_client: TGlideClient):
expected_result = [b"2.5", b"4"]
assert result == expected_result

# Legacy path that exists in only one of the keys
BoazBD marked this conversation as resolved.
Show resolved Hide resolved
result = await json.mget(
glide_client,
[key1, key2],
".b.c",
)
expected_result = [b"true", None]
assert result == expected_result

# JSONPath doesn't exist
BoazBD marked this conversation as resolved.
Show resolved Hide resolved
result = await json.mget(
glide_client,
Expand All @@ -249,7 +263,15 @@ async def test_json_mget(self, glide_client: TGlideClient):
)
assert result == [None, None]

# Keys don't exist
# One key doesn't exist
result = await json.mget(
BoazBD marked this conversation as resolved.
Show resolved Hide resolved
glide_client,
[key1, "{non_existing_key}"],
"$.a",
)
assert result == [b"[1.0]", None]

# Both keys don't exist
result = await json.mget(
glide_client,
["{non_existing_key}1", "{non_existing_key}2"],
Expand Down
Loading