Skip to content

Commit

Permalink
PYTHON: Json.nummultby update (#2578)
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Awawdi <Mawawdi@amazon.com>
  • Loading branch information
Muhammad-awawdi-amazon authored Nov 3, 2024
1 parent 58454c7 commit c2d5e4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/python/glide/async_commands/server_modules/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ async def nummultby(
key: TEncodable,
path: TEncodable,
number: Union[int, float],
) -> Optional[bytes]:
) -> bytes:
"""
Multiplies the JSON value(s) at the specified `path` by `number` within the JSON document stored at `key`.
Expand All @@ -744,7 +744,7 @@ async def nummultby(
number (Union[int, float]): The number to multiply by.
Returns:
Optional[bytes]:
bytes:
For JSONPath (`path` starts with `$`):
Returns a bytes string representation of an array of bulk strings, indicating the new values after multiplication for each matched `path`.
If a value is not a number, its corresponding return value will be `null`.
Expand All @@ -767,7 +767,7 @@ async def nummultby(
"""
args = ["JSON.NUMMULTBY", key, path, str(number)]

return cast(Optional[bytes], await client.custom_command(args))
return cast(bytes, await client.custom_command(args))


async def objlen(
Expand Down
4 changes: 4 additions & 0 deletions python/python/tests/tests_server_modules/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,10 @@ async def test_json_nummultby(self, glide_client: TGlideClient):
result = await json.get(glide_client, key, "$..key1") # type: ignore
assert result == b"[-16500,[140,175],1380]"

# Check 'null' in legacy
with pytest.raises(RequestError):
await json.nummultby(glide_client, key, ".key7", 5)

# Check for non-existent path in legacy
with pytest.raises(RequestError):
await json.nummultby(glide_client, key, ".key10", 51)
Expand Down

0 comments on commit c2d5e4a

Please sign in to comment.